emscripten-core/emsdk

wasm-ld: error: undefined symbol: __secs_to_zone

nukelash opened this issue · 2 comments

I'm using CMake and Emscripten to compile a C++ library to webassembly. Everything is compiling okay, but at the linking stage I get this error:

wasm-ld: error: /usr/local/Cellar/emscripten/3.1.64/libexec/cache/sysroot/lib/wasm32-emscripten/libstandalonewasm-nocatch.a(localtime_r.o): undefined symbol: __secs_to_zone
em++: error: '/usr/local/Cellar/emscripten/3.1.64/libexec/llvm/bin/wasm-ld -o my-project.wasm -L/usr/local/Cellar/emscripten/3.1.64/libexec/cache/sysroot/lib/wasm32-emscripten <my source object files> /usr/local/Cellar/emscripten/3.1.64/libexec/cache/sysroot/lib/wasm32-emscripten/crt1_reactor.o -lGL-getprocaddr -lal -lhtml5 -lstandalonewasm-nocatch -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/xb/kpd82f2566b5vhfyftrysmcc0000gq/T/tmpqqo3n8vllibemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --entry=_initialize --table-base=1 --global-base=1024' failed (returned 1)

My CMakeLists.txt file looks like this:

add_executable(my-project ${MY_SRC})
target_compile_features(my-project PUBLIC cxx_std_17)
target_include_directories(my-project PUBLIC ${MY_INC})
set_target_properties(my-project PROPERTIES CXX_EXTENSIONS OFF)
set_target_properties(my-project PROPERTIES CXX_VISIBILITY_PRESET hidden)
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")

set_target_properties(my-project PROPERTIES COMPILE_FLAGS "-Os -s SIDE_MODULE=1 ")
set_target_properties(my-project PROPERTIES LINK_FLAGS    "-Os -s WASM=1 -s STANDALONE_WASM --no-entry")

And I run like so:

emcmake cmake -S . -B build -G "Unix Makefiles"
cmake --build build

Running objdump -t on libstandalonewasm-nocatch.a shows this, but I'm not sure what to make of it:

./libstandalonewasm-nocatch.a(localtime_r.o):	file format wasm

SYMBOL TABLE:
00000001 g     F CODE .hidden __localtime_r
00000000       F *UND* .hidden __secs_to_zone
00000000       F *UND* .hidden __secs_to_tm
00000000       F *UND* .hidden ___errno_location
00000001  w    F CODE .hidden localtime_r
00000000 l    d  .debug_loc .debug_loc
00000000 l    d  .debug_abbrev .debug_abbrev
00000000         *UND* __stack_pointer
00000000 l    d  .debug_str .debug_str
00000000         *UND* __indirect_function_table
00000000 l    d  .debug_line .debug_line

I'm using MacOS 13.6, emcc 3.1.64 installed through Homebrew, cmake version 3.26.4. Appreciate any guidance!

That's fixed by emscripten-core/emscripten#22316, but I think a new version of emscripten needs to be cut that includes that PR.

We recently releases 3.1.65 which includes this fix.