未定义的引用提升::p rogram_options::abstract_variables_map::operator

undefined reference boost::program_options::abstract_variables_map::operator[]

本文关键字:options abstract variables operator map 引用 未定义 rogram      更新时间:2023-10-16

当我使用以下命令将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库静态链接,并且没有得到未定义的引用。

为什么我在链接共享库时得到未定义的引用?

第 1 步:找出未解析符号的损坏名称(应该已经显示在dlerror()错误消息中)。

第 2 步:找出哪个提升库为该符号提供了定义:

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

第 3 步:将该库添加到 test.so 的链接行。

第四步:利润。