[Regex] Why does this example code not compile?

Using g++ on a GNU Ubuntu Linux 7.04 machine, I am unable to compile the boost example code (saved as test.cpp) at http://www.boost.org/libs/regex/example/snippets/partial_regex_match.cpp Although I can compile my own code which does not use boost, I get a lot of garbled output from the example code...part of which is listed below. Any ideas on what is wrong and how to fix it? test.cpp : (.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[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_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> )]+0xea): 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> > ::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
Thanks. Mike

It means that somewhere along the line you handed some template the wrong type. More cannot really be said with the information you have provided. mike On Tue, 2007-10-30 at 17:28 -0700, Mike Thornton wrote:
Using g++ on a GNU Ubuntu Linux 7.04 machine, I am unable to compile the boost example code (saved as test.cpp) at
http://www.boost.org/libs/regex/example/snippets/partial_regex_match.cpp
Although I can compile my own code which does not use boost, I get a lot of garbled output from the example code...part of which is listed below. Any ideas on what is wrong and how to fix it?
test.cpp : (.text._ZN5boost9re_detail12per l_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[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_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> > >)]+0xea): 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> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
Thanks. Mike _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I tried compiling John Maddock's example code from the URL I provided below, and I get the error below. (I run into a similar error with my own code). Any ideas on how to fix this? System setting? FYI, this is the exact code... /* * * Copyright (c) 1998-2002 * John Maddock * * Use, modification and distribution are subject to the * Boost Software License, Version 1.0. (See accompanying file * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * */ /* * LOCATION: see http://www.boost.org for most recent version. * FILE partial_regex_match.cpp * VERSION see <boost/version.hpp> * DESCRIPTION: regex_match example using partial matches. */ #include <string> #include <iostream> #include <boost/regex.hpp> boost::regex e("(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})"); bool is_possible_card_number(const std::string& input) { // // return false for partial match, true for full match, or throw for // impossible match based on what we have so far... boost::match_results<std::string::const_iterator> what; if(0 == boost::regex_match(input, what, e, boost::match_default | boost::match_partial)) { // the input so far could not possibly be valid so reject it: throw std::runtime_error("Invalid data entered - this could not possibly be a valid card number"); } // OK so far so good, but have we finished? if(what[0].matched) { // excellent, we have a result: return true; } // what we have so far is only a partial match... return false; } int main(int argc, char* argv[]) { try{ std::string input; if(argc > 1) input = argv[1]; else std::cin >> input; if(is_possible_card_number(input)) { std::cout << "Matched OK..." << std::endl; } else std::cout << "Got a partial match..." << std::endl; } catch(const std::exception& e) { std::cout << e.what() << std::endl; } return 0; } and again the error
test.cpp : (.text._ZN5boost9re_detail12pe
r
l_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[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_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_m atch<__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> )]+0xea): 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> > ::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
thanks. mike t. On 10/30/07, Michael Linck <mgl@absolute-performance.com> wrote:
It means that somewhere along the line you handed some template the wrong type. More cannot really be said with the information you have provided.
mike
On Tue, 2007-10-30 at 17:28 -0700, Mike Thornton wrote:
Using g++ on a GNU Ubuntu Linux 7.04 machine, I am unable to compile the boost example code (saved as test.cpp) at
http://www.boost.org/libs/regex/example/snippets/partial_regex_match.cpp
Although I can compile my own code which does not use boost, I get a lot of garbled output from the example code...part of which is listed below. Any ideas on what is wrong and how to fix it?
test.cpp : (.text._ZN5boost9re_detail12per
l_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[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_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_m atch<__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> )]+0xea): 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> > ::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
Thanks. Mike _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Wed, 31 Oct 2007 01:28:47 +0100, Mike Thornton <endoscope@gmail.com> wrote:
Using g++ on a GNU Ubuntu Linux 7.04 machine, I am unable to compile the boost example code (saved as test.cpp) at
http://www.boost.org/libs/regex/example/snippets/partial_regex_match.cpp
Although I can compile my own code which does not use boost, I get a lot of garbled output from the example code...part of which is listed below. Any ideas on what is wrong and how to fix it?
test.cpp :
<snip>
)]+0xea): undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*,
<snip> "undefined reference to" means the linker cannot find the function. You need to tell your linker to include the regex library, called something like `libboost_regex-gcc`. Add it with the -l parameter, e.g. `-lboost_regex-gcc` -- Jonas Hansson

Mike Thornton wrote:
Using g++ on a GNU Ubuntu Linux 7.04 machine, I am unable to compile the boost example code (saved as test.cpp) at
http://www.boost.org/libs/regex/example/snippets/partial_regex_match.cpp
Although I can compile my own code which does not use boost, I get a lot of garbled output from the example code...part of which is listed below. Any ideas on what is wrong and how to fix it?
From the fragment you provided it looks like it may be a linker error, but we need to see the *full command line* and *all* the error to have any clue what the problem is.
Regards, John.
participants (4)
-
John Maddock
-
Jonas Hansson
-
Michael Linck
-
Mike Thornton