Link to home
Create AccountLog in
Avatar of phoffric
phoffric

asked on

Boost Regex Linker Error - Possible bad Boost installation

I have 64-bit Ubuntu installed on VMware over Windows 7 Home Premium 64-bit.

I did the following got some 404 errors midway through, so I did it again later and I thought it went ok:

sudo apt-get install libboost-all-dev

In /usr/lib are these boost libraries:
-rw-r--r-- 1 root root 2626798 Jan  2  2012 libboost_regex.a
lrwxrwxrwx 1 root root      16 Jan  2  2012 libboost_regex-mt.a -> libboost_regex.a
lrwxrwxrwx 1 root root      24 Jan  2  2012 libboost_regex-mt.so -> libboost_regex.so.1.46.1
lrwxrwxrwx 1 root root      24 Jan  2  2012 libboost_regex.so -> libboost_regex.so.1.46.1
-rw-r--r-- 1 root root 1054456 Jan  2  2012 libboost_regex.so.1.46.1

I attached a file, boostlib.txt, which I created with a script in Ubuntu and copied it to Windows; but there are odd chars embedded in the output.

g++ -lboost_regex re2.cpp -o re
(I attached the re2.cpp source code file.)

What do I have to do to fix these linker errors:
/tmp/ccOH7pe5.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
re2.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)]+0x2a): 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/ccOH7pe5.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> > >)':
re2.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> > >)]+0xa2): 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/ccOH7pe5.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_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> > >)':
re2.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC2ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC5ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_]+0x116): 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)'


collect2: ld returned 1 exit status

Open in new window

Thanks.
Paul
boostlib.txt
re2.cpp
Avatar of jkr
jkr
Flag of Germany image

OK, so here are my 2 cents: I don't think it's an installation issue, but maybe a configuration thing. It is usually (in my experience) better to build libraries from scratch, and in your case, it may be worth a try (if it does not help, all you risk is wasting around 10mins of your time).
Avatar of phoffric
phoffric

ASKER

OK, I'll give that a try in a couple days (maybe this weekend).
Take you time, but a boost build is usually an easy thing to do. Even my netbook did that ;o)
New job; steep learning curve. Wish I had the 10 minutes! Deadline for final boot camp aspect is Thursday. Just got over a big hump. Found aho corasick class in the woodwork so I won't be needing regex immediately; but still need to know it for boost spirit. (I hear only masochists learn boost spirit; hope EE has a few of them.)
if i read the errors correctly it is only boost::re_detail::perl_matcher which is missing. did you try to use a perl "flavor" of regex somehow? if yes, can you go without that?

Sara
>> did you try to use a perl "flavor" of regex somehow?
I don't see the word perl in the following source code, but I don't know what is going on under the hood. My attempted build used the following command line:
g++ -lboost_regex re2.cpp -o re
The original instructions said to name the source code file as "re2.cc", but I got a compiler complaint; changing it to "re2.cpp" seemed to be the fix for that problem.
#include<iostream>
#include<boost/regex.hpp>

using namespace std;
using namespace boost;


int main()
{
    regex reg("[\\w]+");
    while (true)
    {
        cout << "Enter a string to split (q=quit): ";
        string str;
        if (!getline(cin, str) || str == "q")
        {
            break;
        }
        const sregex_iterator end;
        for (sregex_iterator it(str.begin(), str.end(), reg); it != end; ++it)
        {
            cout << "\"" << (*it)[0] << "\"" << endl;
        }
    }
}

Open in new window

the re.cc cannot compiled if there is no rule defined in makefile for .cc. i don't think it is an issue.

can you look in regex.h and files coming with regex installation if there is any reference to 'perl'. if in the header, you might have to use a macro for to choose another 'regex matcher'. if in the libraries you might add those libraries to your build command.

Sara
>> the re.cc cannot compiled if there is no rule defined in makefile for .cc.
I don't follow. What makefile?

Turns out on further experimentation, the .cc does work. I think I interpreted the error message wrong. I don't remember what it was, but it was probably related to the entire setup of my command. More on that later.

I grep'd /usr/include/boost for perl and did not get a hit. I then grep'd the libboost libraries and found hits in graph, regex, and wave.
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I corrected the g++ command line which worked without having to make any configuration or installation changes to the system.