title: compiling simple code with boost::regex
body: <p>I'm having trouble compiling the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/regex.hpp&gt;
  
  using namespace std;
  
  int main()
  {
    string s;
    boost::regex re("^{(APPLE|ORANGE),(\\d*)}$");
    boost::cmatch matches;
  
    while(true)
    {
      cout &lt;&lt; "String: ";
      cin &gt;&gt; s;
      if(boost::regex_match(s.c_str(), matches, re))
      {
        for(int i=1; i&lt;matches.size(); i++)
        {
          string match(matches[i].first, matches[i].second);
          cout &lt;&lt; "match[" &lt;&lt; i &lt;&lt; "]:  " &lt;&lt; matches[i] &lt;&lt; endl;
        }
  
      }
      else
      {
        cout &lt;&lt; "no match" &lt;&lt; endl;
      }
    }
    return 0;
  
  }
  </code></pre>
  
  <p>I used the following line to compile with g++:</p>
  
  <pre><code>g++ regexp_test.cpp -o regexp_test.o
  </code></pre>
  
  <p>also tried:</p>
  
  <pre><code>g++ -lboost_regex regexp_test.cpp -o regexp_test.o
  </code></pre>
  
  <p>but I'm getting this long error:</p>
  
  <blockquote>
    <p>/tmp/ccyEpQIk.o: In function <code>bool boost::regex_match&lt;char const*, std::allocator&lt;boost::sub_match&lt;char const*&gt; &gt;, char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;(char const*, char const*, boost::match_results&lt;char const*, std::allocator&lt;boost::sub_match&lt;char const*&gt; &gt; &gt;&amp;, boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt; const&amp;, 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&lt;char const*, std::allocator&lt;boost::sub_match&lt;char const*&gt; &gt;, char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;(char const*, char const*, boost::match_results&lt;char const*, std::allocator&lt;boost::sub_match&lt;char const*&gt; &gt; &gt;&amp;, boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt; const&amp;, boost::regex_constants::_match_flags)]+0x4c): undefined reference to</code>boost::re_detail::perl_matcher >, boost::regex_traits > >::match()'
    /tmp/ccyEpQIk.o: In function <code>boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::assign(char const*, char const*, unsigned int)':
    regexp_test.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::assign(char const*, char const*, unsigned int)]+0x22): undefined reference to</code>boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
    /tmp/ccyEpQIk.o: In function <code>boost::re_detail::perl_matcher&lt;char const*, std::allocator&lt;boost::sub_match&lt;char const*&gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::perl_matcher(char const*, char const*, boost::match_results&lt;char const*, std::allocator&lt;boost::sub_match&lt;char const*&gt; &gt; &gt;&amp;, boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt; const&amp;, 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 to</code>boost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&amp;, boost::regex_constants::_match_flags)'
    collect2: ld returned 1 exit status</p>
  </blockquote>
  
  <p>what am I doing wrong?  </p>