原子复合结构的链接器问题

linker issue with atomic composite struct c++

本文关键字:链接 问题 结构 复合      更新时间:2023-10-16

在Cygwin环境下使用gcc 4.9.3编译以下程序失败

#include <atomic>
struct composite_struct
{
  int anInt;
  int* aPointer;
};
int main()
{
  composite_struct non_atomic_struct;
  non_atomic_struct.anInt = 1001;
  non_atomic_struct.aPointer = new int(1000);
  std::atomic<composite_struct> atomic_struct;
  atomic_struct.store(non_atomic_struct);
  return 0;
}

链接器发送错误消息[...]"undefined reference to '__atomic_store_16'" [...] relocation truncated to fit: R_X86_64_PC32 against undefined symbol '__atomic_store_16'[...]

我在这里看到这个问题存在于早期版本的gcc,它仍然是gcc 4.9.3的情况?

谢谢。

代码存在可移植性问题。

的代码片段
  1. 可以在Visual Studio Express 2013和GNU/Linux系统上编译。
  2. 在gcc 4.9.2或4.9.3的cygwin环境下无法编译(链接失败)