Повысьте regex и запутывающие ошибки

Я пытаюсь использовать Повышение regex, чтобы видеть, имеет ли что-то целое число в нем.

Один из примеров на этой странице

bool validate_card_format(const std::string& s)
{
   static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
   return regex_match(s, e);
}

Здесь существует также, по-видимому, рабочий пример.

Но когда я пробую его на своей машине, я получаю пять страниц нечитабельных ошибок. Что продолжается?

#include 
#include 

using namespace std;

int main(int argc, char *argv[]) {
    static const boost::regex rxInt("[0-9]+");
    string word = "foobar";

    if(boost::regex_match(word, rxInt)) {
        cout << "Integer" << endl;
    } else {
        cout << "Not integer" << endl;
    }

    return 0;
}

Ошибки за $g ++ test.cpp. Там некоторый нормальный путь к grok, что продолжается здесь?

/tmp/ccRNnDit.o: In function `bool boost::regex_match<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, char, boost::regex_traits > >(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags)':
test.cpp:(.text._ZN5boost11regex_matchIN9__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_flagsE[bool boost::regex_match<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, char, boost::regex_traits > >(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags)]+0x82): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::match()'
/tmp/ccRNnDit.o: In function `boost::basic_regex > >::assign(char const*, char const*, unsigned int)':
test.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex > >::assign(char const*, char const*, unsigned int)]+0x2e): undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
/tmp/ccRNnDit.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::perl_matcher(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator, std::allocator > >)':
test.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::perl_matcher(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator, std::allocator > >)]+0x103): 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)'
/tmp/ccRNnDit.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::unwind_extra_block(bool)':
test.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb[boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::unwind_extra_block(bool)]+0x69): undefined reference to `boost::re_detail::put_mem_block(void*)'
/tmp/ccRNnDit.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::match_match()':
test.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE11match_matchEv[boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::match_match()]+0x16d): undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > > const&)'
/tmp/ccRNnDit.o: In function `void boost::re_detail::raise_error > > >(boost::regex_traits_wrapper > > const&, boost::regex_constants::error_type)':
test.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[void boost::re_detail::raise_error > > >(boost::regex_traits_wrapper > > const&, boost::regex_constants::error_type)]+0x70): undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
/tmp/ccRNnDit.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::extend_stack()':
test.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv[boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::extend_stack()]+0x36): undefined reference to `boost::re_detail::get_mem_block()'
/tmp/ccRNnDit.o: In function `boost::cpp_regex_traits::transform(char const*, char const*) const':
test.cpp:(.text._ZNK5boost16cpp_regex_traitsIcE9transformEPKcS3_[boost::cpp_regex_traits::transform(char const*, char const*) const]+0x38): undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform(char const*, char const*) const'
/tmp/ccRNnDit.o: In function `boost::cpp_regex_traits::transform_primary(char const*, char const*) const':
test.cpp:(.text._ZNK5boost16cpp_regex_traitsIcE17transform_primaryEPKcS3_[boost::cpp_regex_traits::transform_primary(char const*, char const*) const]+0x38): undefined reference to `boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const'
/tmp/ccRNnDit.o: In function `boost::re_detail::cpp_regex_traits_implementation::error_string(boost::regex_constants::error_type) const':
test.cpp:(.text._ZNK5boost9re_detail31cpp_regex_traits_implementationIcE12error_stringENS_15regex_constants10error_typeE[boost::re_detail::cpp_regex_traits_implementation::error_string(boost::regex_constants::error_type) const]+0xa6): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
test.cpp:(.text._ZNK5boost9re_detail31cpp_regex_traits_implementationIcE12error_stringENS_15regex_constants10error_typeE[boost::re_detail::cpp_regex_traits_implementation::error_string(boost::regex_constants::error_type) const]+0x127): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
collect2: ld returned 1 exit status

Править: Я думал, что повышение было все шаблонным и только должно было быть включено. Я с тех пор попытался компилировать использование "g ++ test.cpp-L/usr/lib-llibboost_regex-mt" на основе этого:

$ ldconfig -p|grep libboost_regex
    libboost_regex-mt.so.1.38.0 (libc6,x86-64) => /usr/lib/libboost_regex-mt.so.1.38.0
    libboost_regex-mt.so (libc6,x86-64) => /usr/lib/libboost_regex-mt.so

Но я добираюсь "/usr/bin/ld: не может найти-llibboost_regex-mt"

5
задан 3 revs 23 May 2017 в 12:13
поделиться

2 ответа

Когда вы соединяете его, поставьте -l и поместите туда соответствующее имя библиотеки boost.

В данном случае правильное имя библиотеки - 'boost_regex-mt'.

6
ответ дан 14 December 2019 в 08:48
поделиться

Основные ошибки на самом деле следующие:

undefined reference to boost::re_detail::perl_matcher
undefined reference to boost::match_results
undefined reference to boost::re_detail::get_mem_block
1
ответ дан 14 December 2019 в 08:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: