我正在尝试在我的C ++代码中编译一些正则表达式。
我已经跑过ln -s /usr/lib64/libboost_regex.so.1.53.0 /usr/lib/libboost_regex.so
这样才能正确链接。
我正在运行的命令是:g++-4.9 -std=c++11 -O2 -Wall -I/usr/local/include/boost load_and_search.cpp -o bkSearch -L/usr/local/lib/ /usr/local/lib/libboost_serialization.a -lboost_regex
我遇到以下错误:
/tmp/ccrHjY7S.o: In function `boost::re_detail_106700::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> > >::unwind_extra_block(bool)': load_and_search.cpp:(.text._ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb[_ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb]+0x2c): undefined reference to `boost::re_detail_106700::put_mem_block(void*)' /tmp/ccrHjY7S.o: In function `boost::re_detail_106700::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_imp()': load_and_search.cpp:(.text._ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv[_ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv]+0x8): undefined reference to `boost::re_detail_106700::get_mem_block()' load_and_search.cpp:(.text._ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv[_ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv]+0x142): undefined reference to `boost::re_detail_106700::verify_options(unsigned int, boost::regex_constants::_match_flags)' load_and_search.cpp:(.text._ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv[_ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv]+0x183): undefined reference to `boost::re_detail_106700::put_mem_block(void*)' load_and_search.cpp:(.text._ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv[_ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE8find_impEv]+0x409): undefined reference to `boost::re_detail_106700::put_mem_block(void*)' /tmp/ccrHjY7S.o: 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>)': load_and_search.cpp:(.text._ZN5boost12regex_searchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsESD_[_ZN5boost12regex_searchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsESD_]+0x10f): undefined reference to `boost::re_detail_106700::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)' /tmp/ccrHjY7S.o: In function `__gnu_cxx::__normal_iterator<char const*, std::string> boost::re_detail_106700::re_is_set_member<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(__gnu_cxx::__normal_iterator<char const*, std::string>,
__gnu_cxx::__normal_iterator<char const*, std::string>, boost::re_detail_106700::re_set_long<unsigned int> const*, boost::re_detail_106700::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool)': load_and_search.cpp:(.text._ZN5boost16re_detail_10670016re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost16re_detail_10670016re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x17e): undefined reference to `boost::re_detail_106700::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const' load_and_search.cpp:(.text._ZN5boost16re_detail_10670016re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost16re_detail_10670016re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x2ee): undefined reference to `boost::re_detail_106700::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const' /tmp/ccrHjY7S.o: In function `void boost::re_detail_106700::raise_error<boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > >
>(boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::error_type)': load_and_search.cpp:(.text._ZN5boost16re_detail_10670011raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost16re_detail_10670011raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0x8d): undefined reference to `boost::re_detail_106700::get_default_error_string(boost::regex_constants::error_type)' load_and_search.cpp:(.text._ZN5boost16re_detail_10670011raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost16re_detail_10670011raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xc0): undefined reference to `boost::re_detail_106700::raise_runtime_error(std::runtime_error const&)' load_and_search.cpp:(.text._ZN5boost16re_detail_10670011raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost16re_detail_10670011raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xdb): undefined reference to `boost::re_detail_106700::get_default_error_string(boost::regex_constants::error_type)' /tmp/ccrHjY7S.o: In function `boost::re_detail_106700::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> > >::extend_stack()': load_and_search.cpp:(.text._ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv[_ZN5boost16re_detail_10670012perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv]+0x18): undefined reference to `boost::re_detail_106700::get_mem_block()' collect2: error: ld returned 1 exit status make: *** [tools] Error 1
我相信这仍然意味着编译器在libboost_regex文件方面存在问题
这是我要运行的代码示例:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <chrono>
#include <iostream>
#include <boost/regex.hpp>
#include <regex>
#include "BKTree.h"
#include <algorithm>
#include <locale>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
using namespace std::chrono;
void prematch(std::vector<std::vector<std::string> > &parsedCsv, int &i, boost::regex &digitReg, boost::regex &flatNumReg)
{
boost::regex digitReg ("^[^\\d]*(\\d+)");
boost::regex flatNumReg ("(?<=\\bflat\\s|\\bfl\\s|\\bapartment\\s)([a-z0-9]{1,})");
std::string add1 (parsedCsv[i][0]);
boost::smatch digitMatch;
boost::smatch typeMatch;
boost::regex_search (add1,digitMatch,digitReg);
std::string add1String = boost::lexical_cast<std::string>(parsedCsv[i][0]);
boost::regex_search (add1,typeMatch,flatNumReg);
}
有人可以指出我哪里出问题了吗? 我只是在尝试使用boost lib,以便能够使用肯定的回溯。
谢谢, 丹尼尔
答案 0 :(得分:0)
您似乎在针对两个不同版本的boost进行编译和链接:
/usr/include/boost
和/usr/lib64/
中的一个。/usr/local/include/boost
和/usr/local/lib
的人。这可能是您收到链接器错误的原因。
我已经运行
ln -s /usr/lib64/libboost_regex.so.1.53.0 /usr/lib/libboost_regex.so
以便正确链接。
/usr
目录由系统软件包管理器管理,在那里手动管理文件会导致麻烦。不要那样做。
可能发生的情况是您没有安装boost-devel
或libboost-all-dev
或在系统中调用任何boost开发包。该软件包提供了标题和要链接的库。 (您手动创建的链接可能会阻止软件包的安装。)