铛不支持原子:: is_lock_free为类型大于32位的?(clang doesn't

2019-09-30 16:57发布

我有以下情况:

struct A { int a[4]; };
struct B { int x, y; };
int main()
{
    std::cout << std::boolalpha
            << "std::atomic<A> is lock free? "
            << std::atomic<A>{}.is_lock_free() << '\n'
            << "std::atomic<B> is lock free? "
            << std::atomic<B>{}.is_lock_free() << '\n';
}

它编译和运行良好,但如果我提出一个的大小:

struct A { int a[5]; };
struct B { int x, y; };
int main()
{
    std::cout << std::boolalpha
            << "std::atomic<A> is lock free? "
            << std::atomic<A>{}.is_lock_free() << '\n'
            << "std::atomic<B> is lock free? "
            << std::atomic<B>{}.is_lock_free() << '\n';
}

那么铿锵给出了错误:

Undefined symbols for architecture x86_64:
"___atomic_is_lock_free", referenced from:
    _main in atomics.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

什么样的错误,这是什么? 是否需要“is_lock_free”额外库更大结构的工作?


问题修正,用“-latomic”链接标志!

文章来源: clang doesn't support atomic::is_lock_free for types larger than 32 bits?