Boost logo

Boost Users :

Subject: [Boost-users] cann't compile Regular Expressions to Split a String code
From: Eric Lin (kingdavid1_at_[hidden])
Date: 2011-07-10 15:52:29


 Dear Boost programers:

 I copied a piece simple Using Regular Expressions to Split a String
 code from book(c++ cookbook) chapter 4 section 24, page 196-197, Example code 4.33
 ---------------------------------------------------------------------
 // Example 4-33. Using Boost's regular expressions
 #include <iostream>
 #include <string>
 #include <boost/regex.hpp>
 int main() {
 std::string s= "who,lives:in-a,pineapple under the sea?";

 boost::regex re(",|:|-|\\s+"); // Create the reg exp
 boost::sregex_token_iterator // Create an iterator using a
 p(s.begin(), s.end(), re, -1); // sequence and that reg exp
 boost::sregex_token_iterator end; // Crate an end_of_reg_exp
 // marker
 while (p != end)
 std::cout << *p++ << '\n';
 }
 ------------------------
 source code
 http://examples.oreilly.com/9780596007614/
> ---------------------------------------------
> g++ 4-33.cpp
> /tmp/ccx4JXEA.o: In function `boost::basic_regex<char,
> boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char
> const*, char const*, unsigned int)':
> 4-33.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 to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
> /tmp/ccx4JXEA.o: In function `bool
> boost::regex_search<__gnu_cxx::__normal_iterator<char const*,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > > > >, char, boost::regex_traits<char,
> boost::cpp_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> >
> >, boost::match_results<__gnu_cxx::__normal_iterator<char const*,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > > > > >&, 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::basic_string<char, std::char_traits<char>,
> std::allocator<char> > >)':
> 4-33.cpp:(.text._ZN5boost12regex_searchIN9__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_flagsESD_[bool boost::regex_search<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, boost::regex_traits<char, boost::cpp_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> > >, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, 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::basic_string<char, std::char_traits<char>, std::allocator<char> > >)]+0x6c): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::find()'
> /tmp/ccx4JXEA.o: In function
> `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char
> const*, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > >,
> std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char
> const*, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > > > >, boost::regex_traits<char,
> boost::cpp_regex_traits<char> >
> >::perl_matcher(__gnu_cxx::__normal_iterator<char const*,
> std::basic_string<char, std::char_t
> ------------------------------------------
Thanks your help a lot in advance, Eric
                                               


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net