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

时间:2016-10-24 18:56:57

标签: 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)'

我使用cmake链接反对这样的提升:

find_package(Boost COMPONENTS chrono system filesystem thread regex random REQUIRED)    
target_link_libraries (myprog
      ${Boost_REGEX_LIBRARY}
)

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

libboost-regex1.61.0是否已损坏或以某种方式进行了链接更改?

更新:2016年11月14日: Boost的Changelog显示命名空间是从&#34; re_detail&#34;重命名的。到&#34; BOOST_REGEX_DETAIL_NS&#34;。

我使用Kali Rolloing发布,在我看来,installedboost lib 1.61与boost 1.61源不匹配。我将尝试手动安装lib并检查这是否解决了问题。

我更新到1.61,然后更新到1.62。问题仍然存在。 我检查了我的链接器命令并确保&#34; -lboost_regex&#34;出现在行尾。 我只能想到两个问题:

  1. 我的系统有一个旧的boost_regex lib,cmake使用它来链接,尽管cmake宣布使用1.62
  2. 更新标题时,Kali中的boost_regex lib已过时。
  3. 我检查了我的库,它们看起来很好看:

    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
    

    更新:2016年12月9日: 我不是共享对象的导出,但来自提升开发人员的提示指出包装中的混乱。我试着查看当前的库,我猜想lib是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
    

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

2 个答案:

答案 0 :(得分:2)

boost 1.61(及更高版本)是使用较新的编译器进行编译的,该编译器使用_GLIBCXX_USE_CXX11_ABI = 1 .. heh ABI。意味着对于-std = c ++ 11,std::basic_string...变成std::__cxx11::basic_string...(对于std :: list也是如此;请参见gcc Dual ABI documentation)。

由于您的链接器错误声称缺少一个包含std::string的符号(它是std::basic_string<char,std::char_traits<char>,std::allocator<char>>的缩写),因此您正在使用过旧且使用ABI 0的编译器进行编译,或者甚至使用-D_GLIBCXX_USE_CXX11_ABI=0进行显式编译。

无论哪种方式,在您的CXXFLAGS中添加-D_GLIBCXX_USE_CXX11_ABI=1都可以解决问题。

答案 1 :(得分:1)

他有时说的

@Carlo Wood是正确的,您仍然需要检查一件事,以确保您的boost的编译器与调用方相同。我犯了一个错误。我的linux在不同的路径中包括gcc版本4.8.5和gcc版本5.4.0,而我的boost bz2使用的是旧版本,而调用者caffe_ssd使用的是较新版本。 我通过命令boost_1_70_0/bin.v2/project-cache.jamgrep -rn gcc ./找到了关键消息

set "default address-model-32-bit-64-bit-<target-os>linux-<toolset-gcc:version>4.8.5<toolset>gcc" : "5" ;

然后,我检查了呼叫者的gcc版本;它是$CXX,我的%CXX是5.4.0

接下来,你知道我该怎么办;我使用gcc 5.4.0重新编译boost