我正在尝试编译以下代码:
#include <atomic>
#include <iostream>
using namespace std;
int main() {
atomic<unsigned long long> testull {0};
testull++;
cout << testull << endl;
return 0;
}
与
g++48 --std=c++11 atomictest.cpp "-Wl,-rpath=/usr/local/lib/gcc48"
但g++48
因以下消息而失败:
/var/tmp//ccTBLlRL.o: In function `std::__atomic_base<unsigned long long>::fetch_add(unsigned long long, std::memory_order)':
atomictest.cpp:(.text._ZNSt13__atomic_baseIyE9fetch_addEySt12memory_order[_ZNSt13__atomic_baseIyE9fetch_addEySt12memory_order]+0x2e): undefined reference to `__atomic_fetch_add_8'
/var/tmp//ccTBLlRL.o: In function `std::__atomic_base<unsigned long long>::load(std::memory_order) const':
atomictest.cpp:(.text._ZNKSt13__atomic_baseIyE4loadESt12memory_order[_ZNKSt13__atomic_baseIyE4loadESt12memory_order]+0x2a): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
如果我将atomic<unsigned long long>
更改为atomic<unsigned long>
,那么它会毫无问题地编译。知道为什么吗?我在g++48
FreeBSD 9.0