C++ undefined reference to `__atomic_load_16'

僤鯓⒐⒋嵵緔 提交于 2021-02-08 15:47:31

问题


I have linking errors, when trying to do an atomic load of a 16 byte block. I have the following code:

#include <atomic>

struct MyStruct{
  long x; long y;
};

struct X{
  std::atomic<MyStruct> myStruct;
};

int main(){
  X x;
  MyStruct s = atomic_load(&x.myStruct);
}

When I compile this with (g++ version 5.3.1):

g++ --std=c++11 test.cpp

I get the error

/tmp/ccrvzLMq.o: In function `std::atomic<MyStruct>::load(std::memory_order) const':
test.cpp:(.text._ZNKSt6atomicI8MyStructE4loadESt12memory_order[_ZNKSt6atomicI8MyStructE4loadESt12memory_order]+0x1c): undefined reference to `__atomic_load_16'
collect2: error: ld returned 1 exit status

If (following a hint in another post) I add the "-latomic" flag, I get the error "/bin/ld: cannot find /usr/lib64/libatomic.so.1.1.0". And indeed that file does not exist.

Any suggestions?

Gavin

来源:https://stackoverflow.com/questions/37613415/c-undefined-reference-to-atomic-load-16

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!