gpt4 book ai didi

c++ - is_lock_free 未在 gcc 4.7.2 的 std::atomic 中定义?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:04:58 24 4
gpt4 key购买 nike

我遇到这个编译器错误

function std::atomic::is_lock_free() const: error: undefined reference to '__atomic_is_lock_free' 

when compiling code like below using gcc 4.7.2 on linux.

struct S {
int a;
int b;
};


std::atomic<S> s;
cout << s.is_lock_free() << endl;

最佳答案

Atomic API isn't complete in GCC 4.7:

  • When lock free instructions are not available (either through hardware or OS support) atomic operations are left as function calls to be resolved by a library. Due to time constraints and an API which is not finalized, there is no libatomic supplied with GCC 4.7. This is easily determined by encountering unsatisfied external symbols beginning with __atomic_*.

由于 GCC 4.7 没有附带 libatomic,您需要使用另一个编译器,它实际上支持您想要的功能或提供缺少的功能 (sample implementation)。

关于c++ - is_lock_free 未在 gcc 4.7.2 的 std::atomic<T> 中定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15204060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com