sbarakat
November 29th, 2009, 04:41 PM
I am trying to compile a regular expression example that uses the upcoming C++0x standard, but it keeps failing with a rather unhelpful error message:
g++ -Wall -std=c++0x -o "test_regex" "test_regex.cpp"
/tmp/ccGSTlxF.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
test_regex.cpp:(.text._ZNSt3tr111basic_regexIcNS_1 2regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x75): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/ccGSTlxF.o: In function `bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)':
test_regex.cpp:(.text._ZNSt3tr111regex_matchIN9__g nu_cxx17__normal_iteratorIPcSsEEcNS_12regex_traits IcEEEEbT_S7_RKNS_11basic_regexIT0_T1_EESt6bitsetIL m11EE[bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)]+0x79): undefined reference to `bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::match_results<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)'
collect2: ld returned 1 exit status
Compilation failed.
Somewhere in there it says
... undefined reference to `bool std::tr1::regex_match ...
This is the example code I'm working with, sourced from http://www.johndcook.com/cpp_regex.html
#include <tr1/regex>
#include <iostream>
#include <string>
int main()
{
std::string str = "Hello world";
std::tr1::regex rx("ello");
if (regex_match(str.begin(), str.end(), rx))
{
std::cout << "WORKS";
}
return 0;
}I have tried several (http://stackoverflow.com/questions/992176/c-tokenize-a-string-using-a-regular-expression) other (http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c15339/) examples (http://www.codeproject.com/KB/string/TR1Regex.aspx) I have found across the net but they all result with a similar error. I have installed build-essential and running gcc 4.4.1 (which should have TR1).
Can anyone shed any light on the problem?? I am still very new to C++ but come from a PHP background.
g++ -Wall -std=c++0x -o "test_regex" "test_regex.cpp"
/tmp/ccGSTlxF.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
test_regex.cpp:(.text._ZNSt3tr111basic_regexIcNS_1 2regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x75): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/ccGSTlxF.o: In function `bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)':
test_regex.cpp:(.text._ZNSt3tr111regex_matchIN9__g nu_cxx17__normal_iteratorIPcSsEEcNS_12regex_traits IcEEEEbT_S7_RKNS_11basic_regexIT0_T1_EESt6bitsetIL m11EE[bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)]+0x79): undefined reference to `bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::match_results<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)'
collect2: ld returned 1 exit status
Compilation failed.
Somewhere in there it says
... undefined reference to `bool std::tr1::regex_match ...
This is the example code I'm working with, sourced from http://www.johndcook.com/cpp_regex.html
#include <tr1/regex>
#include <iostream>
#include <string>
int main()
{
std::string str = "Hello world";
std::tr1::regex rx("ello");
if (regex_match(str.begin(), str.end(), rx))
{
std::cout << "WORKS";
}
return 0;
}I have tried several (http://stackoverflow.com/questions/992176/c-tokenize-a-string-using-a-regular-expression) other (http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c15339/) examples (http://www.codeproject.com/KB/string/TR1Regex.aspx) I have found across the net but they all result with a similar error. I have installed build-essential and running gcc 4.4.1 (which should have TR1).
Can anyone shed any light on the problem?? I am still very new to C++ but come from a PHP background.