Skip to content

CMake Linker failure under Arch Linux x64 with newest Emscripten #23944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vittorioromeo opened this issue Mar 17, 2025 · 20 comments
Open

CMake Linker failure under Arch Linux x64 with newest Emscripten #23944

vittorioromeo opened this issue Mar 17, 2025 · 20 comments

Comments

@vittorioromeo
Copy link

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.4-git (273f0216fede04f2445367765eaf2aabeeb60d84)
clang version 21.0.0git (/srcdest/llvm-project 148111fdcf0e807fe74274b18fcf65c4cff45d63)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/emscripten-llvm/bin

Building and linking my VRSFML project under Arch Linux x64 works well with Emscripten 3.1.72-1, but linking fails under Emscripten 4.x with the following errors:

wasm-ld: error: unable to find library -lstubs-debug
wasm-ld: error: unable to find library -lc-debug
wasm-ld: error: unable to find library -ldlmalloc-debug
wasm-ld: error: unable to find library -lc++abi-debug-noexcept

These are the CMake variables I use to build:

CMAKE_BUILD_TYPE="RELEASE"
CMAKE_COLOR_DIAGNOSTICS="ON"
CMAKE_CROSSCOMPILING_EMULATOR="/usr/bin/node"
CMAKE_CXX_COMPILER_LAUNCHER=""
CMAKE_CXX_EXTENSIONS="OFF"
CMAKE_CXX_FLAGS="-Ofast -Wall -Wextra -Wpedantic -Wno-ignored-attributes -Wno-unused-command-line-argument"
CMAKE_EXPORT_COMPILE_COMMANDS="ON"
CMAKE_INSTALL_PREFIX:PATH="/home/vromeo/OHW/SFML/build_vrdev_emcc_linux_rel/install"
CMAKE_TOOLCHAIN_FILE="/usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake"
SFML_BUILD_EXAMPLES="ON"
SFML_BUILD_TEST_SUITE="ON"
SFML_ENABLE_LIFETIME_TRACKING="OFF"
SFML_ENABLE_PCH="OFF"
SFML_ENABLE_STACK_TRACES="OFF"
SFML_ENABLE_STDLIB_ASSERTIONS="OFF"
SFML_OPENGL_ES="ON"
SFML_USE_SYSTEM_DEPS="OFF"
SFML_WARNINGS_AS_ERRORS="OFF"

And this is the full output of the linking step which fails:

[200/201] Linking CXX executable bin/tennis.html
FAILED: bin/tennis.html 
: && /usr/lib/emscripten/em++ -Ofast -Wall -Wextra -Wpedantic -Wno-ignored-attributes -Wno-unused-command-line-argument -O3 -DNDEBUG -O3 -flto -SMINIFY_HTML=1 -sASYNCIFY=1 -sASYNCIFY_IGNORE_INDIRECT=1 -pthread -sPTHREAD_POOL_SIZE_STRICT=0 -Wno-limited-postlink-optimizations -Wno-pthreads-mem-growth -sALLOW_MEMORY_GROWTH=1 -sEXIT_RUNTIME=1 -sFETCH=1 -sFORCE_FILESYSTEM=1 -sGL_EXPLICIT_UNIFORM_LOCATION=1 -sMAX_WEBGL_VERSION=2 -sMIN_WEBGL_VERSION=2 -sSTACK_SIZE=4mb -sTOTAL_MEMORY=64mb -sUSE_PTHREADS=1 -sWASM=1 --emrun --shell-file=/home/vromeo/OHW/SFML/emscripten/shell.html --embed-file resources/ball.wav --embed-file resources/sfml_logo.png --embed-file resources/tuffy.ttf examples/tennis/CMakeFiles/tennis.dir/Tennis.cpp.o -o bin/tennis.html  lib/libsfml-audio-s.html  lib/libsfml-graphics-s.html  lib/libvorbisfile.a  lib/libvorbisenc.a  lib/libvorbis.a  lib/libFLAC.a  lib/libogg.a  -lm  lib/libsfml-window-s.html  lib/libsfml-system-s.html  -lEGL  -lGL  lib/libfreetype.a  -lstubs-debug  -lc-debug  -ldlmalloc-debug  -lc++abi-debug-noexcept && :
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libGL-mt-webgl2-getprocaddr.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libGL-mt-webgl2-getprocaddr.a" for subsequent builds)
system_libs:INFO: compiled 4 inputs in 0.17s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libfetch-mt.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libfetch-mt.a" for subsequent builds)
system_libs:INFO: compiled 1 inputs in 0.22s
cache:INFO:  - ok
cache:INFO: generating system asset: sysroot/lib/wasm32-emscripten/lto/crtbegin.o... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/crtbegin.o" for subsequent builds)
system_libs:INFO: compiled 1 inputs in 0.12s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libal.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libal.a" for subsequent builds)
system_libs:INFO: compiled 1 inputs in 0.12s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libhtml5.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libhtml5.a" for subsequent builds)
system_libs:INFO: compiled 5 inputs in 0.12s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libstubs.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libstubs.a" for subsequent builds)
system_libs:INFO: compiled 2 inputs in 0.12s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc-mt.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libc-mt.a" for subsequent builds)
system_libs:INFO: compiled 1129 inputs in 1.90s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libdlmalloc-mt.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libdlmalloc-mt.a" for subsequent builds)
system_libs:INFO: compiled 2 inputs in 0.27s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libcompiler_rt-mt.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libcompiler_rt-mt.a" for subsequent builds)
system_libs:INFO: compiled 162 inputs in 0.66s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc++-mt-noexcept.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libc++-mt-noexcept.a" for subsequent builds)
system_libs:INFO: compiled 57 inputs in 6.02s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libc++abi-mt-noexcept.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libc++abi-mt-noexcept.a" for subsequent builds)
system_libs:INFO: compiled 16 inputs in 2.32s
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/lto/libsockets-mt.a... (this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libsockets-mt.a" for subsequent builds)
system_libs:INFO: compiled 27 inputs in 0.54s
cache:INFO:  - ok
cache:INFO: generating system asset: symbol_lists/7780dfc523e2cd671c67c47c22cb9802d71f3c27.json... (this will be cached in "/home/vromeo/.cache/emscripten/symbol_lists/7780dfc523e2cd671c67c47c22cb9802d71f3c27.json" for subsequent builds)
cache:INFO:  - ok
wasm-ld: error: unable to find library -lstubs-debug
wasm-ld: error: unable to find library -lc-debug
wasm-ld: error: unable to find library -ldlmalloc-debug
wasm-ld: error: unable to find library -lc++abi-debug-noexcept
em++: error: '/opt/emscripten-llvm/bin/wasm-ld -o bin/tennis.wasm examples/tennis/CMakeFiles/tennis.dir/Tennis.cpp.o lib/libsfml-audio-s.html lib/libsfml-graphics-s.html lib/libvorbisfile.a lib/libvorbisenc.a lib/libvorbis.a lib/libFLAC.a lib/libogg.a lib/libsfml-window-s.html lib/libsfml-system-s.html -lGL-mt-webgl2-getprocaddr lib/libfreetype.a -lstubs-debug -lc-debug -ldlmalloc-debug -lc++abi-debug-noexcept -L/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto -L/usr/lib/emscripten/src/lib -lfetch-mt /tmp/emscripten_temp_aplf2s6w/embedded_files.o /home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/crtbegin.o -lGL-mt-webgl2-getprocaddr -lal -lhtml5 -lstubs -lc-mt -ldlmalloc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-mt-noexcept -lsockets-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmp1c8wzm92libemscripten_js_symbols.so --import-memory --shared-memory --export=_emscripten_stack_alloc --export=_emscripten_thread_free_data --export=_emscripten_thread_crashed --export=__funcs_on_exit --export=__wasm_call_ctors --export=_emscripten_tls_init --export=_emscripten_thread_init --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export=emscripten_stack_set_limits --export=_emscripten_thread_exit --export=malloc --export=free --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-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=4194304 --max-memory=2147483648 --initial-memory=67108864 --no-entry --table-base=1 --global-base=1024' failed (returned 1)
ninja: build stopped: subcommand failed.

Searching for one of those libs via locate reports:

❯ locate c++abi-debug-noexcept
/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/libc++abi-debug-noexcept.a
/home/vromeo/.emscripten_cache/sysroot/lib/wasm32-emscripten/libc++abi-debug-noexcept.a

Is this a misconfiguration issue on my side, or is it a regression somewhere in Emscripten or in its CMake modules?

I am not sure how to debug any further.

@vittorioromeo
Copy link
Author

P.S. the error persists even with -DEMSCRIPTEN_FORCE_COMPILERS=ON.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 17, 2025

I think this is an issue with the emscripten is being packaged on your system.

What distro are you using? How is it setting the config file? How is it setting the cache directory? Did this used to work in the past (i.e. is this a regression)?

@sbc100
Copy link
Collaborator

sbc100 commented Mar 17, 2025

The dirctory being passed the linker is /home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto .. which match the location where the libraries are being built to ((this will be cached in "/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/libc++abi-mt-noexcept.a" for subsequent builds))

I do notice that the -debug versions of the libraries are being reported missing though, while the release versions are the ones being built.

If you re-run just the link command does it generate any output? (i.e. /usr/lib/emscripten/em++ -Ofast -Wall -Wextra -Wpedantic -Wno-ignored-attributes -Wno-unused-command-line-argument -O3 -DNDEBUG -O3 -flto -SMINIFY_HTML=1 -sASYNCIFY=1 -sASYNCIFY_IGNORE_INDIRECT=1 -pthread -sPTHREAD_POOL_SIZE_STRICT=0 -Wno-limited-postlink-optimizations -Wno-pthreads-mem-growth -sALLOW_MEMORY_GROWTH=1 -sEXIT_RUNTIME=1 -sFETCH=1 -sFORCE_FILESYSTEM=1 -sGL_EXPLICIT_UNIFORM_LOCATION=1 -sMAX_WEBGL_VERSION=2 -sMIN_WEBGL_VERSION=2 -sSTACK_SIZE=4mb -sTOTAL_MEMORY=64mb -sUSE_PTHREADS=1 -sWASM=1 --emrun --shell-file=/home/vromeo/OHW/SFML/emscripten/shell.html --embed-file resources/ball.wav --embed-file resources/sfml_logo.png --embed-file resources/tuffy.ttf examples/tennis/CMakeFiles/tennis.dir/Tennis.cpp.o -o bin/tennis.html lib/libsfml-audio-s.html lib/libsfml-graphics-s.html lib/libvorbisfile.a lib/libvorbisenc.a lib/libvorbis.a lib/libFLAC.a lib/libogg.a -lm lib/libsfml-window-s.html lib/libsfml-system-s.html -lEGL -lGL lib/libfreetype.a -lstubs-debug -lc-debug -ldlmalloc-debug -lc++abi-debug-noexcept)

@sbc100
Copy link
Collaborator

sbc100 commented Mar 17, 2025

Ah wait.. I see the problem.. you seem to be passing -lstubs-debug -lc-debug -ldlmalloc-debug -lc++abi-debug-noexcept explicitly to the compiler. Those are libraries that get automatically injected by emcc. Are you adding them in your CMakeLists.txt somewhere?

@vittorioromeo
Copy link
Author

@sbc100

What distro are you using?

Arch Linux x64

How is it setting the config file? How is it setting the cache directory?

I have no clue, how can I figure that out?

Did this used to work in the past (i.e. is this a regression)?

Yes -- everything worked fine with Emscripten 3.1.72-1.

If you re-run just the link command does it generate any output?

Yes, same error:

wasm-ld: error: unable to find library -lstubs-debug
wasm-ld: error: unable to find library -lc-debug
wasm-ld: error: unable to find library -ldlmalloc-debug
wasm-ld: error: unable to find library -lc++abi-debug-noexcept
em++: error: '/opt/emscripten-llvm/bin/wasm-ld -o bin/tennis.wasm examples/tennis/CMakeFiles/tennis.dir/Tennis.cpp.o lib/libsfml-audio-s.html lib/libsfml-graphics-s.html lib/libvorbisfile.a lib/libvorbisenc.a lib/libvorbis.a lib/libFLAC.a lib/libogg.a lib/libsfml-window-s.html lib/libsfml-system-s.html -lGL-mt-webgl2-getprocaddr lib/libfreetype.a -lstubs-debug -lc-debug -ldlmalloc-debug -lc++abi-debug-noexcept -L/home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto -L/usr/lib/emscripten/src/lib -lfetch-mt /tmp/emscripten_temp_feq26ds5/embedded_files.o /home/vromeo/.cache/emscripten/sysroot/lib/wasm32-emscripten/lto/crtbegin.o -lGL-mt-webgl2-getprocaddr -lal -lhtml5 -lstubs -lc-mt -ldlmalloc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-mt-noexcept -lsockets-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmp7qb42p67libemscripten_js_symbols.so --import-memory --shared-memory --export=_emscripten_stack_alloc --export=_emscripten_thread_free_data --export=_emscripten_thread_crashed --export=__funcs_on_exit --export=__wasm_call_ctors --export=_emscripten_tls_init --export=_emscripten_thread_init --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export=emscripten_stack_set_limits --export=_emscripten_thread_exit --export=malloc --export=free --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-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=4194304 --max-memory=2147483648 --initial-memory=67108864 --no-entry --table-base=1 --global-base=1024' failed (returned 1)

Ah wait.. I see the problem.. you seem to be passing -lstubs-debug -lc-debug -ldlmalloc-debug -lc++abi-debug-noexcept explicitly to the compiler. Those are libraries that get automatically injected by emcc. Are you adding them in your CMakeLists.txt somewhere?

Nope, I am not passing those anywhere. If I search for them in the entire repository, I can only find them in ./CMakeFiles/3.31.6/CMakeCCompiler.cmake, which is automatically generated:

# ...

set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "GL-getprocaddr;al;html5;stubs-debug;noexit;c-debug;dlmalloc-debug;compiler_rt;c++-noexcept;c++abi-debug-noexcept;sockets")

# ...

@sbc100
Copy link
Collaborator

sbc100 commented Mar 18, 2025

Nope, I am not passing those anywhere. If I search for them in the entire repository, I can only find them in ./CMakeFiles/3.31.6/CMakeCCompiler.cmake, which is automatically generated:

So it looks like the debug libraries were somehow detected and cached, but then the release libraries are actually being using.

Is you clear out the cache and re-run does the same thing happen again?

With emscripten the names of those libraries will be different in debug and release configurations.

@vittorioromeo
Copy link
Author

vittorioromeo commented Mar 19, 2025

Nope, I am not passing those anywhere. If I search for them in the entire repository, I can only find them in ./CMakeFiles/3.31.6/CMakeCCompiler.cmake, which is automatically generated:

So it looks like the debug libraries were somehow detected and cached, but then the release libraries are actually being using.

Is you clear out the cache and re-run does the same thing happen again?

With emscripten the names of those libraries will be different in debug and release configurations.

Even after completely nuking the build folder and /home/vromeo/.cache the issue persists. 😞

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

I guess we need to figure out what CMAKE_C_IMPLICIT_LINK_LIBRARIES is .. and they its caching through debug-specific libraries like that.

Can you perhaps share the full cmake command your ran and then the full make/ninja command you ran order to get that failure?

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

Can you see if IMPORTED_LINK_INTERFACE_LANGUAGES is used anywhere in our project?

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

Yes -- everything worked fine with Emscripten 3.1.72-1.

Could you try to bisect to find out where this broke: https://emscripten.org/docs/contributing/developers_guide.html#bisecting

It does seem like #23537 would be the most likely cultprit but you say that adding -DEMSCRIPTEN_FORCE_COMPILERS=ON didn't work? Did you try deleting all the intermediate files when you tried this?

@vittorioromeo
Copy link
Author

I guess we need to figure out what CMAKE_C_IMPLICIT_LINK_LIBRARIES is .. and they its caching through debug-specific libraries like that.

From here: "Implicit link libraries are those that the compiler (not CMake) itself implicitly links. They are detected by CMake and stored in the variable; the variable is not meant to be modified."

Can you perhaps share the full cmake command your ran and then the full make/ninja command you ran order to get that failure?

cmake .. --preset vrdev_emcc_linux_rel

Relevant presets:

{
  "name": "vrdev_emcc_linux_rel",
  "inherits": "build_base_release",
  "binaryDir": "build_vrdev_emcc_linux_rel",
  "installDir": "${sourceDir}/build_vrdev_emcc_linux_rel/install",
  "cacheVariables": {
    "CMAKE_CROSSCOMPILING_EMULATOR": "/usr/bin/node",
    "CMAKE_CXX_COMPILER_LAUNCHER": "",
    "CMAKE_CXX_FLAGS": "-Ofast $env{CXX_WARNINGS}",
    "CMAKE_TOOLCHAIN_FILE": "/usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake",
    "SFML_OPENGL_ES": "ON"
  }
},
{
  "name": "build_base_release",
  "hidden": true,
  "inherits": "build_base",
  "cacheVariables": {
    "CMAKE_BUILD_TYPE": "RELEASE",
    "SFML_ENABLE_LIFETIME_TRACKING": "OFF",
    "SFML_ENABLE_STACK_TRACES": "OFF",
    "SFML_ENABLE_STDLIB_ASSERTIONS": "OFF"
  }
},
{
  "name": "build_base",
  "hidden": true,
  "generator": "Ninja",
  "cacheVariables": {
    "CMAKE_COLOR_DIAGNOSTICS": "ON",
    "CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
    "CMAKE_CXX_EXTENSIONS": "OFF",
    "CMAKE_CXX_SCAN_FOR_MODULES": "OFF",
    "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
    "SFML_BUILD_EXAMPLES": "ON",
    "SFML_BUILD_TEST_SUITE": "ON",
    "SFML_ENABLE_PCH": "OFF",
    "SFML_USE_SYSTEM_DEPS": "OFF",
    "SFML_WARNINGS_AS_ERRORS": "OFF"
  },
  "environment": {
    "CXX_WARNINGS": "-Wall -Wextra -Wpedantic -Wno-ignored-attributes -Wno-unused-command-line-argument"
  }
}

The ninja command was ninja tennis, that builds the tennis target here. The same linker error appears with any target, it's not specific to this one.

Can you see if IMPORTED_LINK_INTERFACE_LANGUAGES is used anywhere in our project?

None of my CMake files use that explicitly anywhere.

@vittorioromeo
Copy link
Author

vittorioromeo commented Mar 19, 2025

Yes -- everything worked fine with Emscripten 3.1.72-1.

It does seem like #23537 would be the most likely cultprit but you say that adding -DEMSCRIPTEN_FORCE_COMPILERS=ON didn't work? Did you try deleting all the intermediate files when you tried this?

@sbc100

I nuked the build and /home/vromeo/.cache folders again, then ran:

cmake .. --preset vrdev_emcc_linux_rel -DEMSCRIPTEN_FORCE_COMPILERS=ON

And it worked! So there must be something in both the cache and build folder that causes the issue.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

It seems that CMAKE_C_IMPLICIT_LINK_LIBRARIES ends up contains the wrong value.

However for most projects that doesn't seem to be a problem. I can't seem to figure out why your project uses this value but non of our test cmake projects do.

@vittorioromeo
Copy link
Author

It seems that CMAKE_C_IMPLICIT_LINK_LIBRARIES ends up contains the wrong value.

However for most projects that doesn't seem to be a problem. I can't seem to figure out why your project uses this value but non of our test cmake projects do.

Is there anything I can try to narrow down the issue? I'll try reproducing with a smaller part of the project, but it's not trivial...

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

I tried simple project and they don't have this issue, so there must be something interesting/special that your project is doing here that triggers to usage of CMAKE_C_IMPLICIT_LINK_LIBRARIES. We need to figure out what that is, but as you say its non-trivial I guess.

@vittorioromeo
Copy link
Author

I tried simple project and they don't have this issue, so there must be something interesting/special that your project is doing here that triggers to usage of CMAKE_C_IMPLICIT_LINK_LIBRARIES. We need to figure out what that is, but as you say its non-trivial I guess.

Do you have a link to that project? If I compile it, I can at least rule out my environment as being the culprit.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 19, 2025

I just used one of our simple test projects:

$ ./emcmake cmake -S test/cmake/stdproperty/ -B out/cmake -GNinja -DCMAKE_BUILD_TYPE=Release
$ ninja -C out/cmake 

I then verified the -debug variants of the library do exist in the cache:

$ grep -r CMAKE_C_IMPLICIT_LINK_LIBRARIES out/cmake
out/cmake/CMakeFiles/3.30.5/CMakeCCompiler.cmake:set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "GL-getprocaddr;al;html5;stubs-debug;noexit;c-debug;dlmalloc-debug;compiler_rt;c++-noexcept;c++abi-debug-noexcept;sockets")

And that they are not added to the link command:

$ rm out/cmake/helloworld.js && ninja -C out/cmake -v
ninja: Entering directory `out/cmake'
[1/1] : && /usr/local/google/home/sbc/dev/wasm/emscripten/em++ -O3 -DNDEBUG  CMakeFiles/helloworld.dir/main.cpp.o -o helloworld.js   && :

@vittorioromeo
Copy link
Author

vittorioromeo commented Mar 19, 2025

@sbc100: I managed to add a few things from my project to stdproperty and get a reproducible example!

cmake_minimum_required(VERSION 3.16)
project(helloworld)

file(
  DOWNLOAD
  https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.3/CPM.cmake
  ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
  EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

CPMAddPackage(
    NAME ogg
    GITHUB_REPOSITORY xiph/ogg
    GIT_TAG v1.3.5
    SYSTEM TRUE
)

add_executable(helloworld main.cpp)
set_target_properties(helloworld PROPERTIES SUFFIX ".html")

target_link_options(helloworld PRIVATE -flto)
target_link_libraries(helloworld PRIVATE ogg)

Note that commenting out -flto solves the issue. Run CMake like this to reproduce:

cmake .. -GNinja -DCMAKE_CROSSCOMPILING_EMULATOR="/usr/bin/node" -DCMAKE_TOOLCHAIN_FILE="/usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake" -DCMAKE_BUILD_TYPE="RELEASE"  -DCMAKE_CXX_COMPILER_LAUNCHER="" -DCMAKE_CXX_EXTENSIONS="OFF" -DCMAKE_CXX_FLAGS="-Ofast"

@sbc100
Copy link
Collaborator

sbc100 commented Mar 22, 2025

Thanks, I was able to reproduce now. I'm trying to reduce it now.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 22, 2025

Here I the current command I'm using to reproduce:

$  rm -rf build && ./emcmake cmake -S test/cmake/stdproperty -B build -GNinja -DCMAKE_CXX_FLAGS="-Ofast" && ninja -C build -v

We can tell its broken because -lstubs-debug -lc-debug -ldlmalloc-debug -lc++abi-debug-noexcept are explicitly seen on the link command.

Strangely I remove -Ofast from the command line it makes the problem go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants