2010-06-11 9 views
5

Ho cercato di usare libreria Boost, ma ho fallito, vedi il mio codice:Come posso usare la libreria Boost :: regex.hpp in C++?

#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); 
} 

Quando ho provato a compilare io ottenere quei messaggi:

/usr/include/boost/regex/v4 /regex_match.hpp:50: undefined reference to ` boost :: :: re_detail perl_matcher < __gnu_cxx :: __ normal_iterator, std :: allocator>>, std :: allocator, std :: allocator>>>>, boost :: regex_traits>

:: match()'

/usr/include/boost/regex/v4/basic_regex.hpp:425: undefined reference to ` boost :: basic_regex>

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

/usr/include/boost/regex/v4/perl_matcher.hpp:366: undefined reference to ` 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)'

ecc ...

risposta

4

Questi sono errori del linker. La libreria di regex Boost non è una libreria di sola intestazione come shared_ptr (ad esempio) - devi collegarti a .a o .lib o qualsiasi altra libreria binaria.

10

È necessario il collegamento a libboost_regex. Aggiungi -lboost_regex all'interruttore del compilatore se stai utilizzando gcc.

1

Devi collegarti a boost_regex.

Problemi correlati