c++ - x86_64-pc-cygwin-gcc 链接器错误

标签 c++ gcc c++11 linker cygwin

我在我的 cygwin 环境中设置了 x86_64-pc-cygwin-gcc 包来获取最近的 gcc

$ x86_64-pc-cygwin-gcc --version
x86_64-pc-cygwin-gcc (GCC) 4.8.1

我有一个小代码文件,你可以找到here 构建我使用以下行:

 x86_64-pc-cygwin-gcc -std=c++11 -std=gnu++11 TreasureHunter.cpp

编译没问题,但我收到几个关于 std::istream 的链接错误,见下文。这是什么问题,这意味着我在设置过程中错过了包裹吗?

/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x60): undefined reference to `std::istream::operator>>(int&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x60): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `std::istream::operator>>(int&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x7c): undefined reference to `std::istream::operator>>(int&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x7c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `std::istream::operator>>(int&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0xc2): undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, char&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0xc2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, char&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x11e): undefined reference to `std::istream::operator>>(int&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x11e): relocation
truncated to fit: R_X86_64_PC32 against undefined symbol `std::istream::operator>>(int&)'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x2d2): undefined reference to `std::ios_base::Init::Init()'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x2d2): relocation
truncated to fit: R_X86_64_PC32 against undefined symbol `std::ios_base::Init::Init()'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x2ed): undefined reference to `std::ios_base::Init::~Init()'
/cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o:TreasureHunter.cpp:(.text+0x2ed): relocation
truncated to fit: R_X86_64_PC32 against undefined symbol `std::ios_base::Init::~Init()'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: /cygdrive/c/Users/abuisson/AppData/Local/Temp/cc9qeGVh.o: bad reloc address 0x0 in section `.pdata$_ZSt4__lgl'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status

最佳答案

由于您使用 gcc 而不是 g++ 编译 C++ 代码,因此您至少需要将 -lstdc++ 添加到命令行。不过,最好一开始就使用 g++

关于c++ - x86_64-pc-cygwin-gcc 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19816252/

相关文章:

c++ - 嵌套的 unique_ptr 和 STL 容器

java - 从 JNI 发送 float 到 Java 代码添加 2 个数字

c++ - 奇怪的 SDL 内存使用取决于每像素位数

c - 为电子书阅读器设备编写软件

c - 为什么 GCC 对 void-pointer 算术的接受不被认为是一个错误?

C++11 线程不加入

c++ - 我需要宏还是可以使用模板来执行此操作

c++ - 将 native 编译的 C++ DLL 添加到 CLR C++ 项目?

c++ - 回声抑制库?

c++ - 使用 GLM + Answer 将屏幕转换为 3D 世界坐标后结果不佳