Boost logo

Boost Users :

From: Renjie Zhao (bugreport_at_[hidden])
Date: 2006-06-12 09:21:52


After downloading boost_1_33_1, I succeeded in building regex lib with both
VC8 and GCC 3.4.2(mingw special)

1st:
The following code, which is compiled ok using VC8 (cl
a.cpp/I"F:\boost_1_33_1" /EHsc), gives out wrong answer.
Well I think the answer is wrong. Do I misunderstand the regular expression?
It says"no match" while it is supposed to match twice. 01234 and 56972.
If I changes the regex expr to ".*", the code functions well and gives out:
The (0) match is:01234abcd56972

//==================CODE================
#include <string>
#include <boost\regex.hpp>
#include <iostream>

using namespace std;
using namespace boost;
regex expr("([0-9]+)");
const char *src = "01234abcd56972";
int main(int argc, char *argv[])
{
    cmatch m;
    if(regex_match(src, m, expr))
    {
        for(int i = 0; i < m.size(); ++i)
        {
            string msg;
            msg.assign(m[i].first, m[i].second);
            cout<<"The ("<< i <<") match is:"<<msg<<endl;
        }
    }
    else
    {
        cout<<"no match";
    }

    cout<<endl;
    return 0;
}
//=================CODE==================

What is the problem?
Checking the same target string "01234abcd56972" and pattern "([0-9]+)", I
get the expected result. Why?

2nd:
I got a lot of error messages when I tried to compile the same piece of code
with GCC 3.4.2 (mingw-special) under windows 2003
and GCC 4.1.0-3 (shipped with Fedora Core 5) under Linux.
The previous work using Boost::regex is to build the lib, under windows and
linux, the work is done with no error.

------------------error message under windows:-------------------------
F:\projects> g++ a.cpp -I"F:\boost_1_33_1" -o a.exe

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cccPaaaa.o(.text$_ZN5boost11regex_matchIPKcSa
INS_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<char const*,
std::allocator<boost::sub_match<char
 const*> >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >
>(ch
ar const*, char const*, boost::match_results<char const*,
std::allocator<boost::
sub_match<char const*> > >&, boost::basic_regex<char,
boost::regex_traits<char,
boost::cpp_regex_traits<char> > > const&,
boost::regex_constants::_match_flags)]
+0x9a):reg.cpp: undefined reference to `boost::re_detail::perl_matcher<char
cons
t*, std::allocator<boost::sub_match<char const*> >,
boost::regex_traits<char, bo
ost::cpp_regex_traits<char> > >::match()'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cccPaaaa.o(.text$_ZN5boost9re_detail12perl_ma
tcherIPKcSaINS_9sub_matchIS3_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC
1ES3_S3_RNS_13match_resultsIS3_S6_EERKNS_11basic_regexIcSA_EENS_15regex_constant
s12_match_flagsES3_[boost::re_detail::perl_matcher<char const*,
std::allocator<b
oost::sub_match<char const*> >, boost::regex_traits<char,
boost::cpp_regex_trait
s<char> > >::perl_matcher(char const*, char const*,
boost::match_results<char co
nst*, std::allocator<boost::sub_match<char const*> > >&,
boost::basic_regex<char
, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
boost::reg
ex_constants::_match_flags, char const*)]+0xec):reg.cpp: undefined reference
to
`boost::re_detail::perl_matcher<char const*,
std::allocator<boost::sub_match<cha
r const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> >
>::constr
uct_init(boost::basic_regex<char, boost::regex_traits<char,
boost::cpp_regex_tra
its<char> > > const&, boost::regex_constants::_match_flags)'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cccPaaaa.o(.text$_ZN5boost11basic_regexIcNS_1
2regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<ch
ar, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char
con
st*, char const*, unsigned int)]+0x22):reg.cpp: undefined reference to
`boost::b
asic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> >
>::do
_assign(char const*, char const*, unsigned int)'
collect2: ld returned 1 exit status

------------------error message under Linux:-------------------------
[root_at_FC5 project]g++ a.cpp -I"/usr/include" -o a.o
/tmp/cczdwrqd.o: In function `boost::basic_regex<char,
boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char
const*, char const*, unsigned
int)':reg.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 referrence
to'boost::basic_regex<char, boost::regex_traits<char,
boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*,
unsigned int)'
/tmp/cczdwrqd.o: In function `boost::re_detail::perl_matcher<char const*,
std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char,
boost::cpp_regex_traits<char> > >::perl_matcher(char const*, char const*,
boost::match_results<char const*, std::allocator<boost::sub_match<char
const*> > >&, boost::basic_regex<char, boost::regex_traits<char,
boost::cpp_regex_traits<char> > > const&,
boost::regex_constants::_match_flags, char
const*)':reg.cpp:(.text._ZN5boost9re_detail12perl_matcherIPKcSaINS_9sub_matchIS3_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES3_S3_RNS_13match_resultsIS3_S6_EERKNS_11basic_regexIcSA_EENS_15regex_constants12_match_flagsES3_[boost::re_detail::perl_matcher<char
const*, std::allocator<boost::sub_match<char const*> >,
boost::regex_traits<char, boost::cpp_regex_traits<char> >
>::perl_matcher(char const*, char const*, boost::match_results<char const*,
std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char,
boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
boost::regex_constants::_match_flags, char const*)]+0xa5):undefined
reference to'boost::re_detail::perl_matcher<char const*,
std::allocator<boost::sub_match<char const*> >, 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)'
/tmp/cczdwrqd.o: In function `bool boost::regex_match<char const*,
std::allocator<boost::sub_match<char const*> >, char,
boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*,
char const*, boost::match_results<char const*,
std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char,
boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
boost::regex_constants::_match_flags)':reg.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<char const*, std::allocator<boost::sub_match<char const*>
>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char
const*, char const*, boost::match_results<char const*,
std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char,
boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&,
boost::regex_constants::_match_flags)]+0x46):undefined reference
to'boost::re_detail::perl_matcher<char const*,
std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char,
boost::cpp_regex_traits<char> > >::match()'
collect2: ld returns 1

Can some help me? Although I know the question above may seem stupid and
easy to solve.
//Thanks

-- 
This is my Very Signature. Ha, pretty good?


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