【问题标题】:undefined reference boost::program_options::abstract_variables_map::operator[]未定义参考 boost::program_options::abstract_variables_map::operator[]
【发布时间】:2012-04-09 19:41:30
【问题描述】:

当我将 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 库构建另一个程序(不是共享库),但没有得到未定义的引用。

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

【问题讨论】:

  • 也尝试添加-lboost_system
  • 发布进入test.so 的代码,以便我们重现您看到的行为。
  • 那么,最终需要什么?
  • @Nico Schlömer:我不记得了,但问题与 boost 库版本或库类型(共享、静态)与自定义库不匹配有关,诸如此类。如此仔细和精确地重建和链接到我的 boost 库项目很有帮助。

标签: c++ linux boost linker boost-program-options


【解决方案1】:

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

第 2 步:找出 哪些 的 boost 库为该符号提供了定义:

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

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

第 4 步:盈利。

【讨论】:

    猜你喜欢
    • 2012-08-24
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2014-12-16
    相关资源
    最近更新 更多