提升Linux与GCC的链接

时间:2011-10-22 21:39:10

标签: c++ linux gcc boost

我正在尝试使用从存储库安装的boost 1.42在Ubuntu 11.10下编译一个C ++程序(我也试过自己构建boost,但结果与repo-boost相同)。源文件编译但链接器出错...我试了好几个小时但找不到解决方案,也许有人可以帮助我...

这是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是一个也使用boost的库(我在同一系统上编译时没有问题)。所有的库在/ usr / lib中都可以正常...

这是输出ld生成(我使用make 2>输出)http://ubuntuone.com/6QlU7AUZGgLGIu7sHbvDHm

也许库的顺序不正确(我知道boost_filesystem依赖于boost_system,但我不确定其余的)或者我忘了指定一些我的程序需要链接到的其他库...

这真的让我感到烦恼,我觉得我不敢看到它......

1 个答案:

答案 0 :(得分:1)

这些错误消息令人印象深刻:

../../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()'

我在'undefined reference'之前添加了一个换行符......

我认为你应该在任何Boost库之前列出你的库,它使用Boost函数。