【发布时间】:2018-04-01 22:27:49
【问题描述】:
我正在尝试在 cygwin 下使用 g++ 编译一个大型代码库。编译失败,我已将问题简化为以下独立测试用例:
文件 main.cpp:
#include <stdexcept>
int main() {
std::logic_error One("One");
std::logic_error Two(One);
return 0;
}
编译命令及结果:
$ g++ -std=c++11 -static main.cpp
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libstdc++.a(cow-stdexcept.o): In function `std::logic_error::logic_error(std::logic_error const&)':
/usr/src/debug/gcc-6.4.0-1/libstdc++-v3/src/c++11/cow-stdexcept.cc:59: multiple definition of `std::logic_error::logic_error(std::logic_error const&)'
/tmp/ccCSKFES.o:main.cpp:(.text$_ZNSt11logic_errorC1ERKS_[_ZNSt11logic_errorC1ERKS_]+0x0): first defined here
collect2: error: ld returned 1 exit status
该文件在 CentOS 上使用 g++ 5.3.1 和 6.3.1 编译和链接。它无法在 cygwin 下与 g++ 6.3.0 和 6.4.0 链接。如果我省略标志“-static”,它总是编译和链接。 这是cygwin下g ++中的错误,还是我的代码有问题?
【问题讨论】: