linker error when using tr1::regex
Posted
by Max
on Stack Overflow
See other posts from Stack Overflow
or by Max
Published on 2010-05-18T20:06:04Z
Indexed on
2010/05/18
20:10 UTC
Read the original article
Hit count: 552
Hello. 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 functionstd::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 to
std::tr1::basic_regex >::_M_compile()'
/tmp/cce5gojG.o: In functionbool 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>)':
bool 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>)'
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 to
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?
© Stack Overflow or respective owner