I've got a program that uses tr1::regex, and while it compiles, it gives me very verbose linker errors.
Here's my header file MapObject.hpp:
#include <iostream>
#include <string>
#include <tr1/regex>
#include "phBaseObject.hpp"
using std::string;
namespace phObject
{
class MapObject: public phBaseObject
{
private:
string color; // must be a hex string represented as "#XXXXXX"
static const std::tr1::regex colorRX; // enforces the rule above
public:
void setColor(const string&);
(...)
};
}
Here's my implementation:
#include <iostream>
#include <string>
#include <tr1/regex>
#include "MapObject.hpp"
using namespace std;
namespace phObject
{
const tr1::regex MapObject::colorRX("#[a-fA-F0-9]{6}");
void MapObject::setColor(const string& c)
{
if(tr1::regex_match(c.begin(), c.end(), colorRX))
{
color = c;
}
else cerr << "Invalid color assignment (" << c << ")" << endl;
}
(...)
}
and now for the errors:
max#max-desktop:~/Desktop/Development/CppPartyHack/PartyHack/lib$ g++ -Wall -std=c++0x MapObject.cpp
/tmp/cce5gojG.o: In function std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
MapObject.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x61): undefined reference tostd::tr1::basic_regex >::_M_compile()'
/tmp/cce5gojG.o: In function bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)':
MapObject.cpp:(.text._ZNSt3tr111regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcEEEEbT_S8_RKNS_11basic_regexIT0_T1_EESt6bitsetILj11EE[bool std::tr1::regex_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)]+0x53): undefined reference tobool std::tr1::regex_match<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > >, char, std::tr1::regex_traits >(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, std::tr1::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, std::tr1::basic_regex > const&, std::bitset<11u>)'
collect2: ld returned 1 exit status
I can't really make heads or tails of this, except for the undefined reference to std::tr1::basic_regex near the beginning. Anyone know what's going on?
Regex support for C++0x is incomplete and wasn't there for TR1, see the implementation status page for C++0x/TR1.
Boost offers an alternative TR1 implementation as well as the original library it is based on.
The answer is, even though the header is supplied, some of the methods are not supplied.
One could deduce this from Georg's answer, but after thinking up and coding a hundred lines or so based on the assumption that the nifty library was actually provided, one might be too tired for any further deductions.
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I'm new to c++; I have a simple code to check if a string a string is a palindrome:
#include <iostream>
#include <boost/regex.hpp>
#include <sstream>
using namespace std;
using namespace boost;
string PalindromeTwo(string str);
int main(){
cout << PalindromeTwo("A war at Tarawa!");
}
string PalindromeTwo(string str) {
int head = 0;
int tail = str.size() - 1;
boost::regex e("^[a-zA-Z]*$");
stringstream stream;
while(head <= tail){
stream << str.at(head);
string strchar = stream.str();
stream.str(string());
if(!boost::regex_match(strchar,e))
head++;
stream << str.at(tail);
string strchar1 = stream.str();
stream.str(string());
if(!boost::regex_match(strchar1,e))
tail--;
if(strchar.compare(strchar1) != 0)
return "false";
}
return "true";
}
I compiled this code with: g++ -o palin palin.cpp.
Then I got such a long error, I think it's just a little error, but c++ gave me such a long error and I couldn't find any clue from it, any experienced c++ developers could you tell me how to debug in c++ with such a long error?
/tmp/ccEwKTX0.o: In function `bool boost::regex_match<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)':
palin.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[_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]+0x77): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match()'
/tmp/ccEwKTX0.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
palin.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j]+0x2a): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
/tmp/ccEwKTX0.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>)':
palin.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC2ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC5ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_]+0x113): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
collect2: error: ld returned 1 exit status
This is not a compile error btw, it's a linker error, you are not linking with regex library of boost (unlike most of Boost, regex is a compiled library so you need to link it). Better, drop boost::regex and just use std::regex (#include <regex>) which is part of standard library in C++11 (compile with -std=c++11), and all pain will go away.
I'm having trouble compiling the following code:
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;
int main()
{
string s;
boost::regex re("^{(APPLE|ORANGE),(\\d*)}$");
boost::cmatch matches;
while(true)
{
cout << "String: ";
cin >> s;
if(boost::regex_match(s.c_str(), matches, re))
{
for(int i=1; i<matches.size(); i++)
{
string match(matches[i].first, matches[i].second);
cout << "match[" << i << "]: " << matches[i] << endl;
}
}
else
{
cout << "no match" << endl;
}
}
return 0;
}
I used the following line to compile with g++:
g++ regexp_test.cpp -o regexp_test.o
also tried:
g++ -lboost_regex regexp_test.cpp -o regexp_test.o
but I'm getting this long error:
/tmp/ccyEpQIk.o: In function bool boost::regex_match<char const*, std::allocator<boost::sub_match<char const*> >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)':
regexp_test.cpp:(.text._ZN5boost11regex_matchIPKcSaINS_9sub_matchIS2_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SA_RNS_13match_resultsISA_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[bool boost::regex_match<char const*, std::allocator<boost::sub_match<char const*> >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)]+0x4c): undefined reference toboost::re_detail::perl_matcher >, boost::regex_traits > >::match()'
/tmp/ccyEpQIk.o: In function boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
regexp_test.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)]+0x22): undefined reference toboost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
/tmp/ccyEpQIk.o: In function boost::re_detail::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::perl_matcher(char const*, char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, char const*)':
regexp_test.cpp:(.text._ZN5boost9re_detail12perl_matcherIPKcSaINS_9sub_matchIS3_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC2ES3_S3_RNS_13match_resultsIS3_S6_EERKNS_11basic_regexIcSA_EENS_15regex_constants12_match_flagsES3_[_ZN5boost9re_detail12perl_matcherIPKcSaINS_9sub_matchIS3_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC5ES3_S3_RNS_13match_resultsIS3_S6_EERKNS_11basic_regexIcSA_EENS_15regex_constants12_match_flagsES3_]+0xb3): undefined reference toboost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
collect2: ld returned 1 exit status
what am I doing wrong?
Perhaps you don't have the boost binaries, the code compiles here with -lboost_regex. Also, curly brackets are for repeating patterns. For example \d{3} means three digits so you may need to change your regex to:
boost::regex re("^(APPLE|ORANGE),(\\d*)$");
Download the boost libraries then only -lboost_regex will work
if you are using ubuntu then type this in terminal it will install all the boost libraries.
'sudo apt-get install libboost-all-dev'
and do the changes as said by perreal.
I have read many questions like this and I am not 100% sure if mine's any different. I have searched quite a lot for the right answer but most of the answers were around macro gaurds. I had a custom string class that I derived from std::string, and later on since I was using that project in real world so I did not want to derive std::string just for the sake of extending functionality. So I moved the functions from customString.h into utils_string.h. Here is the definition:
#ifndef OPS_TOOLKIT_UTILS_STRING_H
#define OPS_TOOLKIT_UTILS_STRING_H
#include <string>
#include <algorithm>
#include <vector>
namespace utils{
namespace string{
const std::string kilikeDelimiter = "%";
void tolower(std::string& str){
//CODE
}
bool iequals(const std::string& str1,const std::string& str2){
//CODE
}
bool ilike(const std::string& str,const std::string& pattern){
//CODE
}
std::string prependAndAppendILikeDelimiter(const std::string& str) {
//CODE
}
} //namespace string
} //namespace utils
#endif
and I get complains about ...first defined here and here is exact output from compiler. Note: no class here
/tmp/ccCFVTXP.o: In function utils::string::tolower(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
listings.cpp:(.text+0x0): multiple definition ofutils::string::tolower(std::basic_string, std::allocator >&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x0): first defined here
/tmp/ccCFVTXP.o: In function utils::string::iequals(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
listings.cpp:(.text+0x55): multiple definition ofutils::string::iequals(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x55): first defined here
/tmp/ccCFVTXP.o: In function utils::string::ilike(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
listings.cpp:(.text+0x118): multiple definition ofutils::string::ilike(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x118): first defined here
/tmp/ccCFVTXP.o: In function utils::string::prependAndAppendILikeDelimiter(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
listings.cpp:(.text+0x484): multiple definition ofutils::string::prependAndAppendILikeDelimiter(std::basic_string, std::allocator > const&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x484): first defined here
/tmp/ccifZISK.o: In function utils::string::tolower(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
match_count.cpp:(.text+0x0): multiple definition ofutils::string::tolower(std::basic_string, std::allocator >&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x0): first defined here
/tmp/ccifZISK.o: In function utils::string::iequals(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
match_count.cpp:(.text+0x55): multiple definition ofutils::string::iequals(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x55): first defined here
/tmp/ccifZISK.o: In function utils::string::ilike(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
match_count.cpp:(.text+0x118): multiple definition ofutils::string::ilike(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x118): first defined here
/tmp/ccifZISK.o: In function utils::string::prependAndAppendILikeDelimiter(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
match_count.cpp:(.text+0x484): multiple definition ofutils::string::prependAndAppendILikeDelimiter(std::basic_string, std::allocator > const&)'
/tmp/cczDtRdT.o:listing.cpp:(.text+0x484): first defined here
collect2: ld returned 1 exit status
I am sorry for whole mess but I didn't want to miss anything for anyone who has come across similar problem.
One more thing; where it says match_count.cpp *listing.cpp* and listings.cpp it's just using the functions defined in ::utils::string::function()
A header file cannot define code unless it is explicitly inline. Otherwise (because the preprocessor works like a giant copy/paste machine) it is as if the functions are defined once for every file that does a #include.
So add inline to each of those, or put them in a single .cpp, but not in a header.
It may be better to put your functions into a class like this (the following goes to a .h file). It's probably more common that using nested namespace.
#pragma once
#include <string>
namespace utils
{
class StringUtil
{
public:
static void tolower(std::string& str)
{
// code
}
};
}
I installed boost on ubuntu 10.04 by
sudo apt-get install libboost-dev
I think after that I don't need to set any -I and -L flags, so I compile my code by
g++ test.cpp
Here is my test.cpp
#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <boost/config.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
namespace pod = boost::program_options::detail;
int main()
{
//contents
std::stringstream s(
"a = 1\n"
"b = 2\n"
"c = test option\n");
//parameters
std::set<std::string> options;
options.insert("a");
options.insert("b");
options.insert("c");
//parser
for (pod::config_file_iterator i(s, options), e ; i != e; ++i)
{
std::cout << i->value[0] << std::endl;
}
}
I think things will goes well but actually there are some errors:
/tmp/ccNQEbJM.o: In function `boost::program_options::detail::basic_config_file_iterator<char>::basic_config_file_iterator(std::basic_istream<char, std::char_traits<char> >&, std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)':
a.cpp:(.text._ZN5boost15program_options6detail26basic_config_file_iteratorIcEC1ERSiRKSt3setISsSt4lessISsESaISsEEb[boost::program_options::detail::basic_config_file_iterator<char>::basic_config_file_iterator(std::basic_istream<char, std::char_traits<char> >&, std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)]+0x24): undefined reference to `boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)'
a.cpp:(.text._ZN5boost15program_options6detail26basic_config_file_iteratorIcEC1ERSiRKSt3setISsSt4lessISsESaISsEEb[boost::program_options::detail::basic_config_file_iterator<char>::basic_config_file_iterator(std::basic_istream<char, std::char_traits<char> >&, std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)]+0x5f): undefined reference to `boost::program_options::detail::common_config_file_iterator::get()'
/tmp/ccNQEbJM.o: In function `boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >::increment()':
a.cpp:(.text._ZN5boost12eof_iteratorINS_15program_options6detail27common_config_file_iteratorENS1_12basic_optionIcEEE9incrementEv[boost::eof_iterator<boost::program_options::detail::common_config_file_iterator, boost::program_options::basic_option<char> >::increment()]+0x10): undefined reference to `boost::program_options::detail::common_config_file_iterator::get()'
/tmp/ccNQEbJM.o: In function `boost::program_options::detail::basic_config_file_iterator<char>::getline(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
a.cpp:(.text._ZN5boost15program_options6detail26basic_config_file_iteratorIcE7getlineERSs[boost::program_options::detail::basic_config_file_iterator<char>::getline(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)]+0x5b): undefined reference to `boost::program_options::to_internal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status
I can't figure out where and why I went wrong.
You need to link to the Boost program_options library as not everything in Boost is pure templates:
edd#max:/tmp$ cat bpoex.cpp
#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <boost/config.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
namespace pod = boost::program_options::detail;
int main()
{
//contents
std::stringstream s(
"a = 1\n"
"b = 2\n"
"c = test option\n");
//parameters
std::set<std::string> options;
options.insert("a");
options.insert("b");
options.insert("c");
//parser
for (pod::config_file_iterator i(s, options), e ; i != e; ++i)
{
std::cout << i->value[0] << std::endl;
}
}
edd#max:/tmp$ g++ -o bpoex bpoex.cpp -lboost_program_options
edd#max:/tmp$ ./bpoex
1
2
test option
edd#max:/tmp$
I have written a class using std::tr1::regex, and I don't know how to link it. I get (sorry for the large dump...) :
$ g++ DictReader.cpp -std=c++0x
/usr/include/c++/4.4/tr1_impl/regex:2255: warning: inline function ‘bool std::tr1::regex_search(_Bi_iter, _Bi_iter, std::tr1::match_results<_Bi_iter, _Allocator>&, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, std::tr1::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Allocator = std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _Ch_type = char, _Rx_traits = std::tr1::regex_traits<char>]’ used but never defined
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
/tmp/ccgBkWlK.o: In function `DictReader::operator++(int)':
DictReader.cpp:(.text+0xb2a): undefined reference to `bool std::tr1::regex_search<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, 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>)'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_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/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1ERKS3_[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)]+0x60): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
collect2: ld returned 1 exit status.
What should I link against?
This is a linker error, it does not found the function you are using. TR1 is still new so it may not be implemented everywhere. I recommend you to use the boost regex library instead.