zig
zig copied to clipboard
"no-entry" argument not recognized
Zig Version
0.10.0-dev.871+bb05a8a08
Steps to Reproduce
run this:
echo "int add(int a,int b){return a+b;}" > main.c
zig cc main.c -target wasm32-freestanding-none -nostdlib -o binary.wasm -Wl,--no-entry
Expected Behavior
should compile without issue
Actual Behavior
output:
warning: unsupported linker arg: --no-entry
wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start
similarly, if you run
zig cc main.c -target wasm32-freestanding-none -nostdlib -o binary.wasm --no-entry
you get
error: Unknown Clang option: '--no-entry'
so whether you pass the argument to zig cc with --no-entry
or the linker with -Wl,--no-entry
, it doesn't work
Note --no-entry
is a wasm-specific option: https://github.com/llvm/llvm-project/blob/main/lld/docs/WebAssembly.rst#usage
Linking my comment from the PR here for visibility: https://github.com/ziglang/zig/issues/11742#issuecomment-1140243360
As mentioned, the solution is to build a library, rather than an executable.
@Luukdegram If the ship has sailed on flag compatibility with clang, then something must be done to address the usability of this situation. Zig cc is being advertised as an easy entry into the zig world - but incompatibility+bad error messages like this will discourage adoption.
Either
-
wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start
should be changed towasm-ld: error: entry symbol not defined (pass -shared to suppress): _start
- or zig cc should detect the
--no-entry
linker flag and tell you it to use-shared
instead. This way even if the wasm-ld error message isn't changed, people will get directed to do the right thing.
Probably both should be done, so if you are transitioning an existing command to zig cc, it'll tell you the flag is invalid, or if you're working on something new, it'll tell you to add -shared
@danielchasehooper Pardon the late response. I will re-open this ticket so we can improve the error messaging toward the user in the future.
I might have been stuck for hours on this exact problem if I had not found this ticket via Google, and learning that I just need to add the -shared option. Thanks.
im slightly confused by the workaround
jim@gentoo ~/work/gztool $ zig build-exe -I /usr/include/ -O ReleaseSmall -target wasm32-wasi gztool.c -shared
error: unrecognized parameter: '-shared'
jim@gentoo ~/work/gztool $ zig build-exe -I /usr/include/ -O ReleaseSmall -target wasm32-wasi gztool.c --shared
error: unrecognized parameter: '--shared'
here from
jim@gentoo ~/work/gztool $ zig build-exe -I /usr/include/ -O ReleaseSmall -target wasm32-wasi gztool.c ----no-entry
error: unrecognized parameter: '--no-entry'
using a single c file exe https://raw.githubusercontent.com/circulosmeos/gztool/master/gztool.c
I am a first-time zig user also, happy to learn how this can simplify wasm targets
edit: this works
zig cc -I /usr/include/ -target wasm32-freestanding gztool.c -shared
I'm still stuck on this for compiling c libraries to wasm32-wasi, and with cmake there doesn't seem to be an easy fix because using wasm-ld directly causes more issues. This argument is required to build libraries for wasm32-wasi because without it, it errors saying main isn't defined 😕
It seems like this is where the error occurs: https://github.com/ziglang/zig/blob/6bc9c4f716afbb15465f79f84f61221f394fa5b6/src/main.zig#L2224
However I have no idea what the correct fix would be.
Edit: I have found a workaround that actually works but it doesn't support existing build systems like cmake.
zig cc -I ./c/include -target wasm32-wasi -Oz -flto ./c/dec/* ./c/enc/*.c -c -o ./brotli.o
wasm-ld --no-entry --export-all brotli.o -o libbrotli.wasm