Hi.
I am working on porting a C++ framework to WebAssembly and have encountered some issues with dynamic linking. I know static linking is suggested in emscripten, but the framework currently needs the ability to load some modules dynamically.
I successfully compiled a SIDE_MODULE as libbuiltin_modules.so, which should be loadable at runtime using functions like dlopen. However, when I try to compile the main program as a MAIN_MODULE, I receive three warnings about undefined symbols(see the message below). These symbols all start with __sk, which is strange since I don’t have any symbols with that prefix in my code. After some research, I suspect they might be related to a system library.
When I add the -sERROR_ON_UNDEFINED_SYMBOLS=0 flag, the compilation succeeds, but the program aborts at runtime with the same undefined symbol errors.
I also tried compiling with the -sMAIN_MODULE=1 flag. This works fine until I attempt to load the side module with dlopen, at which point I receive the following error message:
Aborted(Assertion failed: undefined symbol '_ZNSt13runtime_errorD1Ev'. Perhaps a side module was not linked in? If this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
Apparently, it is a system library symbol. I suspect it might have been eliminated by using the -sMAIN_MODULE=2 flag. Unfortunately, I can't use the suggested solution (EMCC_FORCE_STDLIBS=1) because compiling with -sMAIN_MODULE leads to three missing symbols.
Any help is appreciated. thanks!
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64 (a1fe390)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 4d8e42ea6a89c73f90941fd1b6e899912e31dd34)
Failing command line in full:
This command is generated by cmake:
/home/sam/emsdk/upstream/emscripten/em++ -fwasm-exceptions -fPIC -g -sMAIN_MODULE=1 --preload-file /home/sam/bmf/big_bunny_10s_30fps.mp4@big_bunny_10s_30fps.mp4 --preload-file /home/sam/bmf/BUILTIN_CONFIG.json@BUILTIN_CONFIG.json --preload-file /home/sam/bmf/build/output/bmf/lib/libbuiltin_modules.so@/lib/libbuiltin_modules.so -sALLOW_MEMORY_GROWTH @CMakeFiles/run_copy_module.dir/objects1.rsp -o ../../../output/bmf/bin/run_copy_module.html @CMakeFiles/run_copy_module.dir/linklibs.rsp
Full link command and output with -v appended:
/home/sam/emsdk/upstream/emscripten/em++ -fwasm-exceptions -fPIC -g -sMAIN_MODULE=1 --preload-file /home/sam/bmf/big_bunny_10s_30fps.mp4@big_bunny_10s_30fps.mp4 --preload-file /home/sam/bmf/BUILTIN_CONFIG.json@BUILTIN_CONFIG.json --preload-file /home/sam/bmf/build/output/bmf/lib/libbuiltin_modules.so@/lib/libbuiltin_modules.so -sALLOW_MEMORY_GROWTH @CMakeFiles/run_copy_module.dir/objects1.rsp -o ../../../output/bmf/bin/run_copy_module.html @CMakeFiles/run_copy_module.dir/linklibs.rsp
error: undefined symbol: __skCPU0AllocatorTag (referenced by root reference (e.g. compiled C/C++ code))
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: ___skCPU0AllocatorTag may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __skCPUManagerTag (referenced by root reference (e.g. compiled C/C++ code))
warning: ___skCPUManagerTag may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __skCPUcopy_stubDispatchTag (referenced by root reference (e.g. compiled C/C++ code))
warning: ___skCPUcopy_stubDispatchTag may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/home/sam/emsdk/node/18.20.3_64bit/bin/node /home/sam/emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpzjmupk3m.json' failed (returned 1)
Hi.
I am working on porting a C++ framework to WebAssembly and have encountered some issues with dynamic linking. I know static linking is suggested in emscripten, but the framework currently needs the ability to load some modules dynamically.
I successfully compiled a SIDE_MODULE as
libbuiltin_modules.so, which should be loadable at runtime using functions like dlopen. However, when I try to compile the main program as a MAIN_MODULE, I receive three warnings about undefined symbols(see the message below). These symbols all start with __sk, which is strange since I don’t have any symbols with that prefix in my code. After some research, I suspect they might be related to a system library.When I add the -sERROR_ON_UNDEFINED_SYMBOLS=0 flag, the compilation succeeds, but the program aborts at runtime with the same undefined symbol errors.
I also tried compiling with the -sMAIN_MODULE=1 flag. This works fine until I attempt to load the side module with dlopen, at which point I receive the following error message:
Apparently, it is a system library symbol. I suspect it might have been eliminated by using the -sMAIN_MODULE=2 flag. Unfortunately, I can't use the suggested solution (EMCC_FORCE_STDLIBS=1) because compiling with -sMAIN_MODULE leads to three missing symbols.
Any help is appreciated. thanks!
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64 (a1fe390)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 4d8e42ea6a89c73f90941fd1b6e899912e31dd34)
Failing command line in full:
This command is generated by cmake:
Full link command and output with
-vappended: