0

program_options を共有ライブラリにリンクしている場合:

g++ -L/path_to_static_boost_libs -shared -o "test.so"  ./test.o   -lboost_program_options

abstract_variables_map::operator[] の参照が未定義のため、ライブラリを読み込めません:

0009b9f8 W int const& boost::program_options::variable_value::as<int>() const
         U boost::program_options::abstract_variables_map::operator[](std::string const&) const
0009b55e W boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_any_cast> >::clone() const

program_options ライブラリが静的にリンクされた別のプログラム (共有ライブラリではない) をビルドしようとしましたが、未定義の参照が取得されませんでした。

共有ライブラリをリンクしているときに未定義の参照が発生するのはなぜですか?

4

1 に答える 1

1

ステップ1:未解決のシンボルのマングルdlerror()された名前を見つけます(エラーメッセージにすでに表示されているはずです)。

ステップ2:どのブーストライブラリがそのシンボルの定義を提供するかを調べます。

nm -A /path_to_static_boost_libs/*.a | grep <mangled-symbol-name>

ステップ3:そのライブラリをのリンク行に追加しますtest.so

ステップ4:利益。

于 2012-04-10T04:08:29.220 に答える