コンパイルしようとしている非常に単純なサンプルプログラムがありますが、リンクエラーが発生します。
プログラム
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
t.wait();
std::cout << "Hello, world!\n";
return 0;
}
コンパイル
私は次のコンパイルオプションを使用しています:
g++ -L/usr/lib -lboost_system -lboost_filesystem -lboost_thread -pthread -I/usr/include timer.cpp -o timer
出力
ダイナミックライブラリが存在し、-Lパスにあることを確認しました。私が得ているエラーは次のとおりです。
/tmp/cc3hJrVk.o: In function `__static_initialization_and_destruction_0(int, int)':
timer.cpp:(.text+0xf0): undefined reference to `boost::system::generic_category()'
timer.cpp:(.text+0xfc): undefined reference to `boost::system::generic_category()'
timer.cpp:(.text+0x108): undefined reference to `boost::system::system_category()'
/tmp/cc3hJrVk.o: In function `boost::system::error_code::error_code()':
timer.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/cc3hJrVk.o: In function `boost::asio::error::get_system_category()':
timer.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
ご覧のとおり、libboost_systemに不適切にリンクしていると、バグが発生するようです。私はテストしたブーストの2つの別々のインストールを持っています、そして私は私のウィットエンドにいます。
助けてくれてありがとう!