1

I'm trying to compile a C++ program under Ubuntu 11.10 using boost 1.42 installed from the repository (I also tried building boost myself, but the result is the same as with the repo-boost). The source files compile but the linker gives errors... I tried for hours but couldn't find a solution to this, maybe someone can help me...

Here's the target from the Makefile

CXX = /usr/bin/g++

LDFLAGS = -L.  \
          -Lpath/to/libMy_Lib.a

CFLAGS = -I.   \
         -Wall \
         -g    \
         -O0

OBJECTS = obj1.o obj2.o

%.o: %.cpp
    $(CXX) -c $*.cpp -o $@ \
         -Wno-deprecated   \
          $(CFLAGS)

all: program

program: $(OBJECTS)
    $(CXX) $^            \
    $(LDFLAGS)           \
    -o myProg            \
    -lboost_regex        \
    -lboost_filesystem   \
    -lboost_date_time    \
    -lboost_system       \
    -lboost_thread       \
    -lMy_Lib

libMy_Lib.a is a library which also uses boost (I had no problems compiling it on the same system). All the libs look ok in /usr/lib...

Here is the output ld generates (I used make 2> output) http://ubuntuone.com/6QlU7AUZGgLGIu7sHbvDHm

Maybe the order of the libraries isn't correct (I know boost_filesystem depends on boost_system, but I'm not sure about the rest) or I forgot to specify some additional libs on which my program needs to link to...

This really buggs me and I feel like I'm blind to not see it...

Adi
  • 562
  • 7
  • 18
  • similiar problem to http://stackoverflow.com/questions/559179/linking-to-boost-regex-in-gcc – fazo Oct 22 '11 at 23:16

1 Answers1

1

Those error messages are impressive:

../../DIAG_DECODER//libDecoder_Element.a(BaseElements_Group.o): In function `bool boost::regex_match<__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)':
BaseElements_Group.cpp:(.text._ZN5boost11regex_matchIN9__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_flagsE[bool boost::regex_match<__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)]+0x4c):
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> > >::match()'

I added a newline before the 'undefined reference'...

I think you should probably list your library, which uses Boost functions, before any of the Boost libraries.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • This was a real slip up of mine (I was working for a time and was tired). Thank you very much :) – Adi Oct 23 '11 at 10:11
  • Also, I just noticed, you should list directories, not files, after `-L`; that then allows libraries specified with `-lname` to be found in the directory. – Jonathan Leffler Oct 23 '11 at 16:02
  • Well by /path/to/myLib.a I was refering to the path to the lib in reality, not to the lib itself... maybe if I put another / at the end of the name it would have been more obvious it was a directory :) – Adi Oct 26 '11 at 20:07
  • So you have a directory `/path/to/My_Lib.a`? Or you have a directory `/path/to/lib/mylib` containing `libMy_Lib.a`? OK; if it was informational and transformed for the purposes of the question, then I withdraw some of the criticism. It was not obvious (at least, to me) from the context that was what you had. – Jonathan Leffler Oct 26 '11 at 21:11
  • Yes, I had a directory containing libMy_Lib.a, but I edited that before posting here. You are right, that was was not very obvious. :) Your criticism is constructive :) Thank you – Adi Oct 27 '11 at 22:01