I encounter this compiler error
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_*
.
Since there is no libatomic
shipped with GCC 4.7 you need to use another compiler which actually supports the features you want or provide the missing features ( sample implementation ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.