6

我尝试使用 Boost 库但失败了,请参阅我的代码:

#include "listy.h"
#include <boost/regex.hpp>
using namespace boost;

ListyCheck::ListyCheck() {

}

ListyCheck::~ListyCheck() {

}

bool ListyCheck::isValidItem(std::string &__item) {
    regex e("(\\d{4}[- ]){3}\\d{4}");

    return regex_match(__item, e);
}

当我尝试编译它时,我收到了这些消息:

/usr/include/boost/regex/v4/regex_match.hpp:50: 未定义引用`boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator >>, std::allocator, std::allocator > > > >, boost::regex_traits >

::匹配()'

/usr/include/boost/regex/v4/basic_regex.hpp:425: 未定义对`boost::basic_regex > 的引用

::do_assign(char const*, char const*, unsigned int)'

/usr/include/boost/regex/v4/perl_matcher.hpp:366: 未定义引用`boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator >>, std::allocator, std::allocator > > > >, boost::regex_traits >

::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'

ETC...

4

4 回答 4

12

您需要链接到libboost_regex. -lboost_regex如果您使用 gcc,请添加到编译器开关。

于 2010-06-11T08:42:48.007 回答
4

这些是链接器错误。Boost 正则表达式库不是诸如 shared_ptr 之类的仅标头库(例如)-您需要链接到 .a 或 .lib 或任何二进制库。

于 2010-06-11T08:43:39.113 回答
1

您必须链接到 boost_regex。

于 2010-06-11T08:44:04.400 回答
0

有类似的问题。

解决方案是通过 cmake 与命令目标链接库链接:

target_link_libraries(boostGraph Boost::regex Boost::date_time Boost::system Boost::filesystem Boost::thread Boost::graph Boost::program_options)

使用此处提供的语法 -lboost_regex 不起作用(至少不适用于 cmake)

根本问题可能是库的不同版本,这会导致问题,即使编译器和链接器确实找到了正则表达式库。

于 2020-05-07T08:19:57.853 回答