Atomic.a not present on single threaded architecture but CMake assumes it is.

/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.

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?

    message("I have atomics")
    message("I do not have atomics")

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


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.