emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.78k stars 3.3k forks source link

error on undefined `main` symbol by default #9640

Closed sbc100 closed 4 years ago

sbc100 commented 5 years ago

Currently emscripten tries to make the main symbol optional, so that some programs (in particular library that export functions but have no entry point) can be built with no main all.

While this feature is convenient if make the code in emscripten more complicated since there is no way to know ahead of time (before linking) if a program has an entry point or not. In particualar there are two places in the codebase were we try to detect if main is present. The first is HAS_MAIN in jsifier, and the second is Building.link_lld. In both cases we get false positives because main is often in EXPORTED_FUNCTIONS even when there is no main.

My proposed solution is to force such users to pass a certain link flag (e.g. -mno-entry or -fno-entry) which will allow emscripten to know what type of program is being built.

sbc100 commented 5 years ago

The cost here is that some users will see undefined symbol: main in their builds and be forces to add -fno-entry.

sbc100 commented 5 years ago

See #9635

parksj10 commented 3 years ago

@sbc100 I'm getting a main export error:

error: undefined symbol: main

and the following compiling options:

rm lttb.wasm
emcc ./lttb.cpp \
  --bind \
  --optimize=3 \
  -Wl,--export-all \
  -Wl,--allow-undefined \
  -s ALLOW_MEMORY_GROWTH=1 \
  -o lttb.wasm

EDIT:----

Adding --no-entry to compilation options solved the error (leaving post up so others can reference, please ignore!)