2026-05-11 7:00 AM - edited 2026-05-11 7:06 AM
I'm trying to use _Atomic with 64 bit objects, but I get a link failure:
undefined reference to `__atomic_load_8'The internet says I need to add an option to the link command:
-latomicHowever, it looks as if that library is not included with the ST tool chain:
cannot find -latomic: No such file or directoryHas anyone managed to get this working?
There are a number of workarounds that could be used here, but it would be much easier to use the native C feature that's been available since C11.
I'm using STM32CubeIDE V 1.18.1 with GNU Tools 13.3
Solved! Go to Solution.
2026-05-11 1:20 PM
Thanks all,
I've worked round the issue by changing my design so that I only need 32 bit atomics.
2026-05-11 7:17 AM
C or C++?
Maybe this helps a bit: https://community.st.com/t5/stm32-mcus-embedded-software/how-atomic-are-the-strd-ldrd-instructions-on-cortex-m4/td-p/884526
2026-05-11 11:29 AM
In addition to the previous reply: the GNU C++ toolchain (likely, also in Clang) defines C-compatible _Atomic(x) so it can be used seamlessly in both C and C++ code:
See ... arm-none-eabi/include/c++/version/stdatomic.h
#if __cplusplus > 202002L
#include <atomic>
#define __cpp_lib_stdatomic_h 202011L
#define _Atomic(_Tp) std::atomic<_Tp>
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
using std::atomic_int8_t;
using std::atomic_uint8_t;
//..... etc ....
2026-05-11 1:20 PM
Thanks all,
I've worked round the issue by changing my design so that I only need 32 bit atomics.
2026-05-11 2:18 PM - edited 2026-05-11 2:19 PM
I suppose the 64b atomic would work with GCC on a 64 bit cpu, with 64b bus.
Because on a 32b machine you cannot access 64 bit memory in one access/cycle,
so just 8...32 bit is possible on a 32 bit cpu.