代码之家  ›  专栏  ›  技术社区  ›  malhobayyeb

如何在C++中使用Booo::ReExx.HPP库?

  •  5
  • malhobayyeb  · 技术社区  · 15 年前

    我尝试使用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<u gnu_cxx::u normal_迭代器, std::分配器>>, STD::分配器, std::分配器>>>>, boost::regex_traits>

    ::Matk()

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

    ::do摷assign(char const*,char const*,unsigned int)'

    /usr/include/boost/regex/v4/perl_matcher.hpp:366: 未定义的引用 ` boost::re_detail::perl_matcher<u gnu_cxx::u normal_迭代器, std::分配器>>, STD::分配器, std::分配器>>>>, boost::regex_traits>

    ::构造_init(boost::basic_regex>gt; 康斯特公司; boost::regex_constants::_match_flags)'

    等。。。

    3 回复  |  直到 15 年前
        1
  •  4
  •   anon    15 年前

    这些是链接器错误。boost regex库不是一个只包含头的库,如shared_ptr(例如),您需要链接到.a或.lib或任何二进制库。

        2
  •  10
  •   kennytm    15 年前

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

        3
  •  1
  •   jopa    15 年前

    你必须连接到Boost®Regex。