我有以下情况:
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”链接标志!