以下代码无法编译
#include <atomic>
#include <functional>
struct SetPair {
uint64_t first;
uint64_t second;
};
int main() {
int N = 1024;
void* MEM = nullptr;
int t = posix_memalign(&MEM, 64, N * sizeof(std::atomic<SetPair>));
auto V = new(MEM) std::atomic<SetPair>[N];
for (int i = 0; i < N; ++i) V[i].store({0,0}, std::memory_order_relaxed);
free(MEM);
return 0;
}
使用以下消息终止编译:
/tmp/ccLkjmPg.o: In function `main':
test.cpp:(.text.startup+0x4e): undefined reference to `__atomic_store_16'
collect2: error: ld returned 1 exit status
使用以下标志编译代码:
g++ -std=c++14 -O3 -I../include test.cpp
如果我将原子的类型从SetPair更改为uint64_t。它工作正常。