// http://en.cppreference.com/w/cpp/atomic/atomic/is_lock_free
#include <iostream>
#include <utility>
#include <atomic>
struct A { int a[100]; };
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';
}
Run Code Online (Sandbox Code Playgroud)
需要添加什么神奇的编译器或链接器标志来解决此问题?
$ clang++ --version
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ clang++ -o atomic atomic.cpp -std=c++14 -O2 -Wall -pedantic -lpthread
Undefined symbols for architecture x86_64:
"___atomic_is_lock_free", referenced from:
_main in atomic-e3a97a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
编辑(2019.01.16): even -latomic不起作用
$ make atomic
$ clang++ -o atomic atomic.cpp -std=c++14 -O2 -Wall -pedantic -lpthread -latomic
ld: library not found for -latomic
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1334 次 |
| 最近记录: |