2017-10-20 99 views
0

我正尝试在cygwin下用g ++编译一个大的代码库。编译失败,我已经减少了问题,下面的自包含的测试案例:使用g ++在cygwin下进行静态编译时出现多重定义错误

文件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 ++中的错误,还是我的代码中有错?

回答

0

您可以

g++ -Wl,--allow-multiple-definition -static -Wall main.cpp 

尝试但是,如果我没记错的C++异常不上Cygwin的静态编译工作得很好。