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

**URL:** https://discourse.cmake.org/t/atomic-a-not-present-on-single-threaded-architecture-but-cmake-assumes-it-is/4951
**Category:** Development
**Created:** [February 3, 2022, 5:09am UTC](https://discourse.cmake.org/t/atomic-a-not-present-on-single-threaded-architecture-but-cmake-assumes-it-is/4951 "2022-02-03T05:09:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SamuraiCrow](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuraicrow/32/2774_2.png) [@SamuraiCrow](https://discourse.cmake.org/u/SamuraiCrow)
#### Post date: [February 3, 2022, 5:09am UTC](https://discourse.cmake.org/t/atomic-a-not-present-on-single-threaded-architecture-but-cmake-assumes-it-is/4951/1 "2022-02-03T05:09:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 3, 2022, 12:18pm UTC](https://discourse.cmake.org/t/atomic-a-not-present-on-single-threaded-architecture-but-cmake-assumes-it-is/4951/2 "2022-02-03T12:18:07Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![SamuraiCrow](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuraicrow/32/2774_2.png) [@SamuraiCrow](https://discourse.cmake.org/u/SamuraiCrow)
#### Post date: [February 3, 2022, 2:19pm UTC](https://discourse.cmake.org/t/atomic-a-not-present-on-single-threaded-architecture-but-cmake-assumes-it-is/4951/3 "2022-02-03T14:19:01Z")

</div>

```auto
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](https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-14) at /opt/wasi-sdk/share/cmake/wasi-sdk.cmake (assuming /opt is your install directory on Linux).

Invoked with:

```auto
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.

---

<div class="post-metadata">

### Author: ![SamuraiCrow](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuraicrow/32/2774_2.png) [@SamuraiCrow](https://discourse.cmake.org/u/SamuraiCrow)
#### Post date: [February 7, 2022, 3:01pm UTC](https://discourse.cmake.org/t/atomic-a-not-present-on-single-threaded-architecture-but-cmake-assumes-it-is/4951/4 "2022-02-07T15:01:34Z")

</div>

LibC++'s version of atomic.cpp and the atomic header do not support single-threaded environments like WASI.
