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 ++中的錯誤,還是我的代碼中有錯?