在Linux上使用GCC加强链接 [英] Boost linking on Linux with GCC
问题描述
我试图在Ubuntu 11.10下使用从存储库安装的boost 1.42编译C ++程序(我也试着自己构建boost,但结果与repo-boost相同)。源文件编译但连接器给出错误...我尝试了几个小时,但无法找到解决方案,也许有人可以帮助我...
这里是来自Makefile的目标
pre code> 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)
全部:程序
程序:$(OBJECTS)
$(CXX)$ ^ \
$(LDFLAGS)\
-o myProg \
-lboost_regex \
-lboost_filesystem \
-lboost_date_time \
-lboost_system \
-lboost_thread \
-lMy_Lib
libMy_Lib.a是一个库,它也使用boost(我没有问题在同一个系统上编译它)。所有的libs在/ usr / lib中都可以正常运行。
这里是输出ld generate(我用make 2>输出) http://ubuntuone.com/6QlU7AUZGgLGIu7sHbvDHm
也许库的顺序不是正确的(我知道boost_filesystem取决于boost_system,但我不知道其余的),或者我忘了指定一些额外的库,我的程序需要链接到...
这些错误信息是令人印象深刻的: ../../ DIAG_DECODER // libDecoder_Element.a(BaseElements_Group.o):在函数`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< 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< std :: allocator< char>>>>>& ;, boost :: basic_regex< char,boost :: regex_traits< char,boost :: cpp_regex_traits< char>>> const&; boost: :regex_constants :: _ match_flags)] + 0x4c):
未定义引用boost :: re_detail :: perl_matcher <__ gnu_cxx :: _ normal_iterator ,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函数的库。
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.
这篇关于在Linux上使用GCC加强链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!