Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no-entry" argument not recognized #11045

Closed
danielchasehooper opened this issue Mar 3, 2022 · 7 comments · Fixed by #17815
Closed

"no-entry" argument not recognized #11045

danielchasehooper opened this issue Mar 3, 2022 · 7 comments · Fixed by #17815
Labels
arch-wasm 32-bit and 64-bit WebAssembly error message This issue points out an error message that is unhelpful and should be improved. zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@danielchasehooper
Copy link
Contributor

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

@danielchasehooper danielchasehooper added the bug Observed behavior contradicts documented or intended behavior label Mar 3, 2022
@matu3ba
Copy link
Contributor

matu3ba commented Mar 3, 2022

@Vexu Vexu added arch-wasm 32-bit and 64-bit WebAssembly zig cc Zig as a drop-in C compiler feature labels Mar 3, 2022
@Vexu Vexu added this to the 0.10.0 milestone Mar 3, 2022
danielchasehooper added a commit to danielchasehooper/zig that referenced this issue May 27, 2022
Only works with wasm32 target.
Usage:
zig cc main.c -target wasm32-freestanding-none -o binary.wasm -Wl,--no-entry

Fixes ziglang#11045
@Luukdegram
Copy link
Member

Linking my comment from the PR here for visibility:
#11742 (comment)

As mentioned, the solution is to build a library, rather than an executable.

@Luukdegram Luukdegram closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2022
@danielchasehooper
Copy link
Contributor Author

danielchasehooper commented May 28, 2022

@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

  1. wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start should be changed to wasm-ld: error: entry symbol not defined (pass -shared to suppress): _start
  2. 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

@Luukdegram
Copy link
Member

@danielchasehooper
Pardon the late response. I will re-open this ticket so we can improve the error messaging toward the user in the future.

@Luukdegram Luukdegram reopened this Jun 3, 2022
@Vexu Vexu added error message This issue points out an error message that is unhelpful and should be improved. and removed bug Observed behavior contradicts documented or intended behavior labels Jun 3, 2022
@williamstein
Copy link
Contributor

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.

@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Sep 14, 2022
@jnorthrup
Copy link

jnorthrup commented Mar 8, 2023

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

@theoparis
Copy link

theoparis commented Jul 12, 2023

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:

zig/src/main.zig

Line 2224 in 6bc9c4f

fatal("unsupported linker arg: {s}", .{arg});

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly error message This issue points out an error message that is unhelpful and should be improved. zig cc Zig as a drop-in C compiler feature
Projects
None yet
8 participants