以下代码无法链接:
#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;
}
出现以下错误:
/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'
如果我将 unsigned long-s 替换为大小不超过 int 的任何内容,则编译得很好。使用 g++ 4.7.2 。你知道这是为什么吗?
用命令编译:
g++ dryn.cpp --std=c++11