1

I get the error:

wasm-ld: error: lto.tmp: undefined symbol: main

Because I try to compile a C or C++ file with Clang compiler to wasm32-wasi. I have defined:

-Wl,--no-entry

But it still insists of there being main() function present. The only way I can stop that is by doing:

-nostdlib

Which works, but then I can't include any library headers or use anything. I was wondering why I can't disable the main entry point without disabling support for the standard library? This goes both for C and C++. My full command is:

zig c++ ./WebAssemblyCompilationTesting.cpp -o myoutput.wasm --target=wasm32-wasi -Wl,--no-entry -g0 -Wl,--strip-all -O3 -nostdlib
3
  • zig isn't Clang - and C++ isn't zig - so please explain your command-line for us. Commented Aug 24 at 0:49
  • Also, as far as Google will take me, I'm only seeing --target=wasm32-wasi as an option for Rust - not for Zig or Clang. I honestly don't know what's going on here. Commented Aug 24 at 0:52
  • @Dai I'm pretty sure they're the same. zig c++ is using clang++. And I got it to work with -g0 -Wl,--strip-all. Actually I'm not sure the -g0 is necessary, -Wl,--stripall did it. Made it go from 700kb to 300 bytes. Commented Aug 24 at 3:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.