1

動的リンクはすべて問題ないアプリケーションがありますが、静的リンクを使用してコンパイルしようとすると、以下のエラーが発生します。

私のアプリはブーストスレッド asio を使用しています

エラー:

/tmp/ccMj2fHI.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x237): undefined reference to `boost::system::get_system_category()'
test.cpp:(.text+0x243): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x24f): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x25b): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x267): undefined reference to `boost::system::get_system_category()'
/tmp/ccnCWj1O.o: In function `__static_initialization_and_destruction_0(int, int)':
AccountSe.cpp:(.text+0x507): undefined reference to `boost::system::get_system_category()'
AccountSe.cpp:(.text+0x513): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x51f): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x52b): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x537): undefined reference to `boost::system::get_system_category()'

また、すべてのソース ファイルで同様のエラーが発生します。

コマンド ラインをコンパイルします。

g++ -L /usr/lib/ -lboost_system -lboost_thread -o newserver -static /usr/lib/libboost_thread.a /usr/lib/libboost_system.a stdafx.cpp test.cpp AccountSe.cpp ... -lpthread -std= c++0x

4

1 に答える 1

6

ほとんどの場合、リンクの順序が原因です。Boost ライブラリはコマンド ラインで最初に表示され、それらを処理した後、リンカは参照されていないシンボルを破棄してから、他のオブジェクト ファイルとライブラリのリンクに進みます。

ソースの、前にブースト ライブラリを配置します-lpthread

于 2013-01-03T15:36:54.870 に答える