2017-10-20 13 views
0

g ++で大きなコードベースをcygwinでコンパイルしようとしています。コンパイルが失敗し、私は次の自己完結型のテスト・ケースに問題が低下している:gg ++での静的コンパイルで多重定義エラーが発生しました

ファイル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"を省略すると、常にコンパイルとリンクが行われます。 これはg ++のcygwinのバグですか?それともコードに何か問題がありますか?

答えて

0

あなたは

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

で試すことができます。しかし、私は右覚えていればC++の例外は、cygwinの上の静的ビルドでは非常にうまく機能しません。

関連する問題