问题
I've got the following:
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';
}
It compiles and works well, but if I raise the size of A:
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';
}
Well clang gives error:
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)
What kind of error is this? Does it require extra library for "is_lock_free" to work with bigger structures?
Problem fixed, use "-latomic" linking flag!
来源:https://stackoverflow.com/questions/45346246/clang-doesnt-support-atomicis-lock-free-for-types-larger-than-32-bits