Closed ritch2022 closed 1 year ago
What is in hello.cpp? Do you have main entry point?
If not, the error message is designed to point you to the solution: To build in STANDALONE_WASM mode without a main(), use emcc --no-entry
Here is the hello.cpp
// hello.cpp
#include <stdio.h>
int main() {
printf("hello, world!\n");
return 0;
}
I just followed the post section: https://v8.dev/blog/emscripten-standalone-wasm#running-in-wasm-runtimes
That is very strange.. that above works fine for me:
$ cat hello.cpp
// hello.cpp
#include <stdio.h>
int main() {
printf("hello, world!\n");
returclang version 14.0.6n 0;
}
$ emcc hello.cpp -O3 -o hello.wasm
$ node a.out.js
I notice that you are using some kind of distro package for emscripten and that seems like it might be the most likely reason for you failure. In fact, I can see now that your clang version looks completely wrong. It seem to be clang version 14.0.6
but emscripten 3.1.24 expects clang 16.
Can you try installing emscripten via emsdk to see if that fixes your issue. You might also want to file a bug with the package maintainer. When you use the wrong llvm version emscripten should also be warning you about. You should see something like this:
emcc: warning: LLVM version for clang executable "/usr/bin/clang" appears incorrect (seeing "14.0", expected "16.0") [-Wversion-check]
I'm not sure how you could not be seeing that warning.
cc @Ericson2314 who I think was involved with the NixOS package that it looks like you are using?
update:
I found that I used an unstable version of the Nixpkgs repository, So I set it to version 22.11(commit: 285b3ff0660640575186a4086e1f8dc0df2874b5) and re-installed emscripten.
Now emcc version is 3.1.17
❯ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.17-git
clang version 14.0.6
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /nix/store/vml9va213nbs46wikw85sm94mv3bbw1x-emscripten-llvm-3.1.17/bin
but get the same error
❯ emcc hello.cpp -O3 -o hello.wasm
error: undefined symbol: main/__main_argc_argv (referenced by top-level compiled C/C++ code)
warning: Link with `-sLLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _main may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
warning: To build in STANDALONE_WASM mode without a main(), use emcc --no-entry
Error: Aborting compilation due to previous errors
emcc: error: '/nix/store/mldqcwj80jlcpi8g7bicknq7pxw4sqz9-nodejs-18.12.1/bin/node /nix/store/8da379da6xjlh7w65zbyrhsvks00585p-emscripten-3.1.17/share/emscripten/src/compiler.js /tmp/tmp1ipo2b8c.json' failed (returned 1)
That still looks like likely llvm version mismatch. Emscripten 3.1.17 is supposed to be used with llvm 15:
$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.17 (fbc532773d84d2bd7da876275671970e792ad1cd)
clang version 15.0.0 (https://github.com/llvm/llvm-project 17e4c217b66305e60657a48f10fe3c428c2fe4d2)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/google/home/sbc/dev/wasm/emsdk/upstream/bin
See the clang version 15.0.0
line above. (Also note that emscripten always depends on a specific version of llvm, not an official release).
Please try using emsdk, at least just temporarily. If that fixes your issue then this is likely bug in the NixOS packaging and not an emscripten issue.
Using emsdk, it works. It should be issue of Nixpkgs, I will try feedback this.
Great news! Should we close this issue now?
ok I will close it.
I'm new to emscripten, and try to work with standalone WebAssembly. Followed by the blog: https://v8.dev/blog/emscripten-standalone-wasm, but failed. Error msg is
error: undefined symbol: main/__main_argc_argv (referenced by top-level compiled C/C++ code)
.Version of emscripten/emsdk:
Full link command and output with
-v
appended: