简体   繁体   中英

Boost linking on Linux with GCC

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM