如何在C ++中使用Boost :: regex.hpp库?

时间:2010-06-11 08:40:28

标签: c++ regex boost boost-regex

我尝试使用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:   未定义的引用   `升压:: re_detail :: perl_matcher&LT; __ gnu_cxx :: __ normal_iterator,   std :: allocator&gt; &gt;中   的std ::分配器,   std :: allocator&gt; &GT; &GT; &gt;中   boost :: regex_traits&gt;

     
    

::匹配()'

  
     

/usr/include/boost/regex/v4/basic_regex.hpp:425:   未定义的引用   `boost :: basic_regex&gt;

     
    

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

  
     

/usr/include/boost/regex/v4/perl_matcher.hpp:366:   未定义的引用   `升压:: re_detail :: perl_matcher&LT; __ gnu_cxx :: __ normal_iterator,   std :: allocator&gt; &gt;中   的std ::分配器,   std :: allocator&gt; &GT; &GT; &gt;中   boost :: regex_traits&gt;

     
    

:: construct_init(boost :: basic_regex&gt;&gt;     常量和放大器;,     升压:: regex_constants :: _ match_flags)'

  

等...

3 个答案:

答案 0 :(得分:10)

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

答案 1 :(得分:4)

这些是链接器错误。 Boost正则表达式库不是像header_ptr那样的仅头文件库(例如) - 您需要链接.a或.lib或任何二进制库。

答案 2 :(得分:1)

您必须链接到boost_regex。

相关问题