首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libboost_regex未编译

libboost_regex未编译
EN

Stack Overflow用户
提问于 2018-11-21 11:32:09
回答 1查看 1.2K关注 0票数 0

我正试图在我的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

我得到以下错误:

代码语言:javascript
复制
/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文件有问题。

这是我试图运行的代码示例:

代码语言:javascript
复制
#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,以便能够使用正回溯。

谢谢,丹尼尔

EN

回答 1

Stack Overflow用户

发布于 2018-11-21 12:10:22

看起来,您编译并链接到了两个不同版本的boost:

  1. 一个来自/usr/include/boost/usr/lib64/
  2. 另一个来自/usr/local/include/boost/usr/local/lib

这可能是导致链接器错误的原因。

我已经运行了ln -s /usr/lib64/libboost_regex.so.1.53.0 /usr/lib/libboost_regex.so,以便正确地链接它。

/usr目录由您的系统包管理器管理,手动管理文件会导致麻烦。别那么做。

可能发生的情况是,您没有安装boost-devellibboost-all-dev,也没有在系统中调用任何boost开发包。该包提供了要链接的标题和库。(手动创建的链接可能会阻止包的安装。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53411176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档