regex_search.hpp:56: 对 `boost::re_detail_106100::perl_matcher 的未定义引用

new*_*gen 3 c++ regex boost

从 boost 1.58 更新到 1.61 后,链接失败并出现以下错误:

In function `bool boost::regex_search<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>)':
/usr/include/boost/regex/v4/regex_search.hpp:56: undefined reference to `boost::re_detail_106100::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::find()'
CMakeFiles/havoc.dir/src/helpers.cpp.o: In function `boost::re_detail_106100::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>)':
/usr/include/boost/regex/v4/perl_matcher.hpp:382: undefined reference to `boost::re_detail_106100::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
Run Code Online (Sandbox Code Playgroud)

我使用 cmake 来链接 boost,如下所示:

find_package(Boost COMPONENTS chrono system filesystem thread regex random REQUIRED)    
target_link_libraries (myprog
      ${Boost_REGEX_LIBRARY}
)
Run Code Online (Sandbox Code Playgroud)

我搜索了 boost 的变更日志,但找不到任何可能导致 cmake 链接失败的具体内容。就像我说的:它与 1.58 完美配合。

libboost-regex1.61.0 是否损坏或者链接是否以某种方式发生了变化?

更新:2016 年 11 月 14 日: Boost 的变更日志显示命名空间从“re_detail”重命名为“BOOST_REGEX_DETAIL_NS”。

我使用 Kali Rolloing 版本,在我看来,安装的 boost lib 1.61 与 boost 1.61 源不匹配。我将尝试手动安装该库并检查这是否可以解决问题。

我更新到1.61,后来又更新到1.62。问题依然存在。我检查了链接器命令并确保“-lboost_regex”出现在该行的末尾。我只能想到两个问题:

  1. 我的系统在某处有一个旧的 bo​​ost_regex 库,cmake 使用它来链接,尽管 cmake 宣布使用 1.62
  2. Kali 中的 boost_regex 库已过时,而标头已更新。

我检查了我的图书馆,它们看起来不错:

newgen@kali:/usr/lib/i386-linux-gnu$ ls -al | grep boost | grep regex
-rw-r--r--   1 root   root    2390702 Nov 12 19:46 libboost_regex.a
lrwxrwxrwx   1 root   root         24 Nov 12 19:46 libboost_regex.so -> libboost_regex.so.1.62.0
    -rw-r--r--   1 root   root    1107284 Nov 12 19:46 libboost_regex.so.1.62.0
Run Code Online (Sandbox Code Playgroud)

更新:2016 年 12 月 9 日: 我不导出共享对象,但 boost 开发人员的提示指出包装中存在混乱。我尝试查看当前的库,我猜测该库是 v1.58,而标头是 v1.62。

/usr/lib/i386-linux-gnu$ nm --dynamic libboost_regex.so.1.62.0 | grep   regex_search

0005d4e0 W _ZN5boost12regex_searchINS_16re_detail_10620016mapfile_iteratorESaINS_9sub_matchIS2_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SA_RNS_13match_resultsISA_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE
Run Code Online (Sandbox Code Playgroud)

在 Kali Linux Bug Tracker 中打开了一个 Bug: https://bugs.kali.org/view.php?id=3765

Car*_*ood 5

boost 1.61(及更高版本)是使用较新的编译器编译的,该编译器使用 _GLIBCXX_USE_CXX11_ABI=1 .. heh ABI。这意味着 -std=c++11std::basic_string...变为std::__cxx11::basic_string...(对于 std::list 同样如此;请参阅gcc Dual ABI 文档)。

由于您的链接器错误声称缺少包含std::string(是 的缩写std::basic_string<char,std::char_traits<char>,std::allocator<char>>)的符号,因此您要么使用太旧且使用 ABI 0 的编译器进行编译,要么甚至使用-D_GLIBCXX_USE_CXX11_ABI=0.

无论哪种方式,添加-D_GLIBCXX_USE_CXX11_ABI=1到您的 CXXFLAGS 应该可以解决问题。