/opt/wasi-sdk/bin/clang --target=wasm32-wasi --sysroot=/opt/wasi-sdk/share/wasi-sysroot -mno-atomics -DCHECK_FUNCTION_EXISTS=__atomic_fetch_add_4 -Werror=unguarded-availability-new CMakeFiles/cmTC_44e46.dir/CheckFunctionExists.c.obj -o cmTC_44e46 -latomic && :
wasm-ld: error: unable to find library -latomic
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake needs to detect if atomic.h and atomic.a are present on an architecture before trying to link against them, let alone making sure they work.
ben.boeckel
(Ben Boeckel (Kitware))
February 3, 2022, 12:18pm
2
Can you provide a minimal CMakeLists.txt
that shows this problem? I see a few flags that are coming from the project this error is from (the -Werror=
at least). Is the project also putting atomic
into this somehow because I’m not seeing where CMake is adding this from a quick search?
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(none)
if(CMAKE_HAS_ATOMICS)
message("I have atomics")
else()
message("I do not have atomics")
endif()
When used with toolchain file found in wasi-sdk-14 at /opt/wasi-sdk/share/cmake/wasi-sdk.cmake (assuming /opt is your install directory on Linux).
Invoked with:
cmake . -DWASI_SDK_PREFIX=/opt/wasi-sdk -DCMAKE_C_FLAGS="--sysroot=/opt/wasi-sdk/share/wasi-sysroot" --toolchain /opt/wasi-sdk/share/cmake/wasi-sdk.cmake
Edit
This test doesn’t fail so the problem must be elsewhere. Sorry to waste your time.
LibC++'s version of atomic.cpp and the atomic header do not support single-threaded environments like WASI.