[quickjs-devel] Re: How to compile hello.c

  • From: kimown <kimown@xxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Fri, 30 Aug 2019 21:56:27 +0800 (CST)

I know how to generate executable, from `make` command output
```
cp examples/hello.js examples/hello233.js
echo "console.log('233');" > examples/hello233.js
./qjsc -e -fno-string-normalize -fno-map -fno-promise -fno-typedarray 
-fno-typedarray -fno-regexp -fno-json -fno-eval -fno-proxy -fno-date -o 
hello233.c examples/hello233.js
gcc -g -Wall -MMD -MF .obj/hello.o.d -Wno-array-bounds -D_GNU_SOURCE 
-DCONFIG_VERSION=\"2019-08-18\" -O2 -flto -c -o .obj/hello233.o hello233.c
gcc -g -flto -o examples/hello233 .obj/hello233.o .obj/quickjs.o 
.obj/libregexp.o .obj/libunicode.o .obj/cutils.o .obj/quickjs-libc.o -lm -ldl
./examples/hello233
```

At 2019-08-28 14:29:39, "Vincent Chan" <okcdz@diverse.space> wrote:
I don’t have a linux machine. Perhaps you should try to link the .o file in 
directory named .obj . 


On Aug 27, 2019, at 4:50 PM, kimown <kimown@xxxxxxx> wrote:


Thanks, I compile it in linux, so I have to use gcc, but gcc throw error.

gcc -o hello libquickjs.a hello.c

/tmp/ccWCp9HS.o: In function `main':
hello.c:(.text+0x10): undefined reference to `JS_NewRuntime'
hello.c:(.text+0x20): undefined reference to `JS_NewContextRaw'
hello.c:(.text+0x30): undefined reference to `JS_AddIntrinsicBaseObjects'
hello.c:(.text+0x45): undefined reference to `js_std_add_helpers'
hello.c:(.text+0x62): undefined reference to `js_std_eval_binary'
hello.c:(.text+0x6e): undefined reference to `js_std_loop'
hello.c:(.text+0x7a): undefined reference to `JS_FreeContext'
hello.c:(.text+0x86): undefined reference to `JS_FreeRuntime'
collect2: error: ld returned 1 exit status

At 2019-08-27 16:06:57, "Vincent Chan" <okcdz@diverse.space> wrote:
You need to make libquickjs.a first:


$ make libquickjs.a


Then, compile you’re hello.c and link the libquickjs.a


$ clang hello.c -g -o hello ./libquickjs.a



On Aug 27, 2019, at 4:04 PM, kimown <kimown@xxxxxxx> wrote:


hello.c
/* File generated automatically by the QuickJS compiler. */


I can generate hello.c from qjsc, but can I compile it using gcc or clang?



Other related posts: