将boost正则表达式库与gcc 5.2.0链接时未定义的引用错误

时间:2016-04-08 07:14:56

标签: boost g++ linker-errors undefined-reference boost-regex

以下代码使用GCC 4.9.2成功编译,没有任何警告:

#include <memory>
#include <string>
#include <boost/regex.hpp>

int main()
{
boost::wregex wregex;
std::wstring text = L"foobar";
return boost::regex_match(text, wregex);
}

命令运行是:

g++ -I /opt/boost/x86_64/1.60.0/include -L /opt/boost/x86_64/1.60.0/lib test.cc  -lboost_regex

但与GCC 5.2.0一起使用时显示以下错误:

/tmp/cc3L5WWc.o: In function `bool boost::regex_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >, wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >(__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::match_results<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > > >&, boost::basic_regex<wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&, boost::regex_constants::_match_flags)': test.cc:(.text._ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKwNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEEESaINS_9sub_matchISB_EEEwNS_12regex_traitsIwNS_16cpp_regex_traitsIwEEEEEEbT_SJ_RNS_13match_resultsISJ_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKwNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEEESaINS_9sub_matchISB_EEEwNS_12regex_traitsIwNS_16cpp_regex_traitsIwEEEEEEbT_SJ_RNS_13match_resultsISJ_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x80): undefined reference to `boost::re_detail_106000::perl_matcher<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >::match()'/tmp/cc3L5WWc.o: In function `boost::re_detail_106000::perl_matcher<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >::perl_matcher(__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::match_results<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > > >&, boost::basic_regex<wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >)': 
 test.cc:(.text._ZN5boost16re_detail_10600012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKwNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEEESaINS_9sub_matchISC_EEENS_12regex_traitsIwNS_16cpp_regex_traitsIwEEEEEC2ESC_SC_RNS_13match_resultsISC_SF_EERKNS_11basic_regexIwSJ_EENS_15regex_constants12_match_flagsESC_[_ZN5boost16re_detail_10600012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKwNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEEEESaINS_9sub_matchISC_EEENS_12regex_traitsIwNS_16cpp_regex_traitsIwEEEEEC5ESC_SC_RNS_13match_resultsISC_SF_EERKNS_11basic_regexIwSJ_EENS_15regex_constants12_match_flagsESC_]+0x116): undefined reference to `boost::re_detail_106000::perl_matcher<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<wchar_t const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > >::construct_init(boost::basic_regex<wchar_t, boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > > const&, boost::regex_constants::_match_flags)'
 collect2: error: ld returned 1 exit status

0 个答案:

没有答案