C ++ 11 undefined reference to `__atomic_store_16 '

The following code cannot reference:

#include <atomic> struct A { unsigned long a; unsigned long b; }; struct B { void set(A tmp) { _a.store(tmp); } std::atomic<A> _a; }; int main() { B b; b.set(A()); return 0; } 

With the following error:

 /tmp/cc8gyaZM.o: In function `std::atomic<A>::store(A, std::memory_order)': dryn.cpp: (.text._ZNSt6atomicI1AE5storeES0_St12memory_order[_ZNSt6atomicI1AE5storeES0_St12memory_order]+0x3e): undefined reference to `__atomic_store_16' 

If I replaced unsigned long-s with anything that matches the size of an int, that is just fine. Using g ++ 4.7.2. Do you have an idea why?

Compiled with command:

 g++ dryn.cpp --std=c++11 
+7
c ++ c ++ 11 stdatomic
source share
1 answer

As Zeta replied:

The atomic API is not complete in GCC 4.7:

  • When instructions for unlocking are unavailable (either through hardware or OS support), atomic operations remain as function calls that will be resolved by the library. Due to time limitations and an API that is not completed, the libatomic shipped with GCC 4.7 is missing. This can be easily determined by encountering unsatisfied external characters starting with __atomic_* .

Since there is no libatomic shipped with GCC 4.7, you need to use another compiler that actually supports the functions you want or provide the missing functions ( sample implementation ).

+5
source share

All Articles