nginx / unit-wasm

Development libraries for writing WebAssembly modules for NGINX Unit
https://unit.nginx.org/
Apache License 2.0
38 stars 8 forks source link

Error adding symbols: archive has no index #29

Open alexmro opened 1 day ago

alexmro commented 1 day ago

When I try to build some of the examples with clang, using clang -o myapp.wasm luw-echo-request.c -lunit-wasm, I get this error:

/usr/bin/ld: /lib/x86_64-linux-gnu/libunit-wasm.a: error adding symbols: archive has no index; run ranlib to add one
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ac000 commented 1 day ago

You will need a command more like

$ clang -fno-strict-aliasing --target=wasm32-wasi --sysroot=/usr/wasm32-wasi -I../../src/c/include -Wl,--no-entry,--export=__heap_base,--export=__data_end,--export=malloc,--export=free,--stack-first,-z,stack-size=$((8*1024*1024)) -mexec-model=reactor --rtlib=compiler-rt -o myapp.wasm luw-echo-request.c -L../../src/c -lunit-wasm

-I../../src/c/include is the location of the unit-wasm.h header file -L../../src/c is the location of the libunit-wasm.a static library

The actual command that compiles the luw-echo-request.c is

clang -O2 -Wall -Wextra -Wdeclaration-after-statement -Wvla -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Wimplicit-function-declaration -Wimplicit-int -Wint-conversion -std=gnu11 -g -fno-common -fno-strict-aliasing --target=wasm32-wasi --sysroot=/usr/wasm32-wasi -I../../src/c/include -Wl,--no-entry,--export=__heap_base,--export=__data_end,--export=malloc,--export=free,--stack-first,-z,stack-size=$((8*1024*1024)) -mexec-model=reactor --rtlib=compiler-rt -o luw-echo-request.wasm luw-echo-request.c -L../../src/c -lunit-wasm

If you are able to build libunit-wasm and the C examples, i.e.

$ make examples

or

$ make V=1 examples

To see exactly what's being done.

Then you should be good to go with the above command...

alexmro commented 8 hours ago

Thanks, my final command was

clang -O2 -Wall -Wextra -Wdeclaration-after-statement -Wvla -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Wimplicit-function-declaration -Wimplicit-int -Wint-conversion -std=gnu11 -g -fno-common -fno-strict-aliasing --target=wasm32-wasi --sysroot= -I../../src/c/include -Wl,--no-entry,--export=__heap_base,--export=__data_end,--export=malloc,--export=free,--stack-first,-z,stack-size=$((8*1024*1024)) -mexec-model=reactor --rtlib=compiler-rt -o luw-echo-request.wasm luw-echo-request.c -L../../src/c -lunit-wasm

I had to include another directory