我试图在std::atomic<>
中使用struct sigaction
和std::vector
但我的测试用例在Clang和GCC中都失败并出现链接器错误。这是为什么?我支持所有类型,甚至是非基本类型。
#include <atomic>
#include <vector>
#include <signal.h>
std::vector<std::atomic<struct sigaction> > vec (1);
int main() {
struct sigaction sa = { };
vec[0].store (sa);
sa = vec[0].load ();
return 0;
}
见http://coliru.stacked-crooked.com/a/df4cfcbe48ecc992。结果是
g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out ; g++ -v 2>&1 |grep 'gcc version'
clang++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out ; clang++ -v 2>&1 |grep 'clang version'
/tmp/ccgNkprP.o: In function `main':
main.cpp:(.text.startup+0x41): undefined reference to `__atomic_store'
main.cpp:(.text.startup+0x5f): undefined reference to `__atomic_load'
collect2: error: ld returned 1 exit status
gcc version 5.2.0 (GCC)
/tmp/main-c75098.o: In function `main':
main.cpp:(.text+0x96): undefined reference to `__atomic_store'
main.cpp:(.text+0xb1): undefined reference to `__atomic_load'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang version 3.6.0 (tags/RELEASE_360/final 235480)