Проблема компиляции программы с использованием библиотеки регулярных выражений
Я попытался скомпилировать программу boost, которая использовала библиотеку boost regex на моем linux box. в нем есть все необходимые заголовки и библиотеки. Программа отказывается компилировать, выбрасывая огромный дамп шаблона вывода. Я использую следующую команду для компиляции программы.
Пожалуйста, посоветуйте, как исправить ниже.
g ++ regex.cc -I / usr / local / include / boost / -L / usr / local / lib -lboost_regex -o regex
Вот вывод компилятора.
ravit@ravit-laptop:~$ g++ regex.cc -I/usr/local/include/boost/ -L/usr/local/lib -lboost_regex -o regex
In file included from /usr/local/include/boost/regex/v4/perl_matcher.hpp:582,
from /usr/local/include/boost/regex/v4/regex.hpp:88,
from /usr/local/include/boost/regex.hpp:31,
from regex.cc:19:
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp: In member function ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’:
/usr/local/include/boost/regex/v4/perl_matcher_non_recursive.hpp:180: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_all_states() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:323: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_prefix() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:207: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_imp() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:180: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/regex_match.hpp:50: instantiated from ‘bool boost::regex_match(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/regex_match.hpp:82: instantiated from ‘bool boost::regex_match(const std::basic_string<charT, ST, SA>&, boost::match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with ST = std::char_traits<char>, SA = std::allocator<char>, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
regex.cc:30: instantiated from here
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
вот фрагмент кода, взятый из той же документации по регулярному выражению Boost
#include <boost/regex.hpp>
#include <iostream>
void
print_captures(const std::string& regx,
const std::string& text)
{
boost::regex e(regx);
boost::smatch what;
std::cout << "Expression: \"" << regx << "\"\n";
std::cout << "Text: \"" << text << "\"\n";
if(boost::regex_match(text, what, e, boost::match_extra))
{
unsigned i, j;
std::cout << "** Match found **\n Sub-Expressions:\n";
for(i = 0; i < what.size(); ++i)
std::cout << " $" << i << " = \"" << what[i] << "\"\n";
std::cout << " Captures:\n";
for(i = 0; i < what.size(); ++i)
{
std::cout << " $" << i << " = {";
for(j = 0; j < what.captures(i).size(); ++j)
{
if(j)
std::cout << ", ";
else
std::cout << " ";
std::cout << "\"" << what.captures(i)[j] << "\"";
}
std::cout << " }\n";
}
}
else
std::cout << "** No Match found **\n";
}
int main(int , char* [])
{
print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee");
print_captures("a(b+|((c)*))+d", "abd");
print_captures("(.*)bar|(.*)bah", "abcbar");
print_captures("(.*)bar|(.*)bah", "abcbah");
print_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party");
print_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party");
print_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party");
print_captures("^(\\w+)\\W+(?>(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party");
return 0;
}
2 ответа
Перейдите к файлу regex.cc, строка 30 (regex.cc:30: создан здесь) и STARE (перекрестная проверка с примерами из документации, которая работает), пока не станет ясно, что вы сделали неправильно. Кажется, что вы вызываете back() и empty () для чего-то, что не поддерживает эти операции. Учитывая [50] в конце этих сообщений об ошибках [которые также говорят, что это не классовый тип], вы, вероятно, забыли проиндексировать массив. (т.е. вы написали array.empty () вместо array[i].empty()).
ошибка: запрос на член '.....' в '......' часто вызывается либо использованием . когда вы должны использовать -> или добавление () при объявлении, когда вы не должны, например:
TheClass myTheClass();
вместо
TheClass myTheClass;