Std::atomic_thread_fence有未定义的引用
std::atomic_thread_fence has undefined reference
在Ubuntu 12.04系统上,当我尝试编译以下代码时:
#include <atomic>
int a;
int main()
{
a = 0;
std::atomic_thread_fence(std::memory_order_acquire);
a = 1;
}
得到如下错误信息:
g++ test.cpp -std=c++0x
/tmp/ccayKntC.o: In function `main': test.cpp:(.text+0x14): undefined reference to `std::atomic_thread_fence(std::memory_order)' collect2: ld returned 1 exit status
在使用clang++
编译时也会发生这种情况。由于这是一个链接器错误,我猜我的libstdc++版本缺乏必要的功能。然而,其他原子操作似乎可以工作。
我正在使用Ubuntu 12.04。我想知道我的系统设置是否有问题,是否缺少libstdc++的功能,或者可能是其他东西。理想情况下,我希望能够解决这个问题。
这实际上是一个在4.7分支中修复的错误:
- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51038
我想你应该用__sync_synchronize
或者__asm__ __volatile__ ( "mfence" ::: "memory" )
之类的
有些人喜欢对他们需要的同步操作非常严格,但我认为一直使用mfence
对于常见情况就足够了。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用