Note that there are some explanatory texts on larger screens.

plurals
  1. POlinker error when using tr1::regex
    primarykey
    data
    text
    <p>I've got a program that uses <code>tr1::regex</code>, and while it compiles, it gives me very verbose linker errors.</p> <p>Here's my header file MapObject.hpp:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;tr1/regex&gt; #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&amp;); (...) }; } </code></pre> <p>Here's my implementation:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;tr1/regex&gt; #include "MapObject.hpp" using namespace std; namespace phObject { const tr1::regex MapObject::colorRX("#[a-fA-F0-9]{6}"); void MapObject::setColor(const string&amp; c) { if(tr1::regex_match(c.begin(), c.end(), colorRX)) { color = c; } else cerr &lt;&lt; "Invalid color assignment (" &lt;&lt; c &lt;&lt; ")" &lt;&lt; endl; } (...) } </code></pre> <p>and now for the errors:</p> <blockquote> <p>max@max-desktop:~/Desktop/Development/CppPartyHack/PartyHack/lib$ g++ -Wall -std=c++0x MapObject.cpp<br> /tmp/cce5gojG.o: In function <code>std::tr1::basic_regex&lt;char, std::tr1::regex_traits&lt;char&gt; &gt;::basic_regex(char const*, unsigned int)': MapObject.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex&lt;char, std::tr1::regex_traits&lt;char&gt; &gt;::basic_regex(char const*, unsigned int)]+0x61): undefined reference to</code>std::tr1::basic_regex >::_M_compile()'<br> /tmp/cce5gojG.o: In function <code>bool std::tr1::regex_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, char, std::tr1::regex_traits&lt;char&gt; &gt;(__gnu_cxx::__normal_iterator&lt;char const*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char const*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::tr1::basic_regex&lt;char, std::tr1::regex_traits&lt;char&gt; &gt; const&amp;, std::bitset&lt;11u&gt;)':<br> MapObject.cpp:(.text._ZNSt3tr111regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcEEEEbT_S8_RKNS_11basic_regexIT0_T1_EESt6bitsetILj11EE[bool std::tr1::regex_match&lt;__gnu_cxx::__normal_iterator&lt;char const*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, char, std::tr1::regex_traits&lt;char&gt; &gt;(__gnu_cxx::__normal_iterator&lt;char const*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;char const*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::tr1::basic_regex&lt;char, std::tr1::regex_traits&lt;char&gt; &gt; const&amp;, std::bitset&lt;11u&gt;)]+0x53): undefined reference to</code>bool std::tr1::regex_match&lt;__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&lt;__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&amp;, std::tr1::basic_regex > const&amp;, std::bitset&lt;11u>)'<br> collect2: ld returned 1 exit status</p> </blockquote> <p>I can't really make heads or tails of this, except for the <code>undefined reference to std::tr1::basic_regex</code> near the beginning. Anyone know what's going on?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload