【问题标题】:Boost linking on Linux with GCC使用 GCC 增强 Linux 上的链接
【发布时间】:2011-10-22 21:39:10
【问题描述】:

我正在尝试使用从存储库安装的 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,但我不确定其余的)或者我忘记指定我的程序需要链接到的一些其他库...

这真的让我很烦,我觉得我看不见它……

【问题讨论】:

标签: c++ linux gcc boost


【解决方案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()'

我在“未定义的引用”之前添加了一个换行符...

我认为您可能应该在任何 Boost 库之前列出使用 Boost 函数的库。

【讨论】:

  • 这是我的一个真正的失误(我工作了一段时间,很累)。非常感谢:)
  • 另外,我刚刚注意到,您应该在-L 之后列出目录,而不是文件;然后允许在目录中找到使用-lname 指定的库。
  • 好吧,/path/to/myLib.a 我指的是实际库的路径,而不是库本身...也许如果我在名称末尾加上另一个 /更明显的是它是一个目录:)
  • 所以你有一个目录/path/to/My_Lib.a?或者你有一个目录/path/to/lib/mylib 包含libMy_Lib.a?好的;如果它是为了问题的目的而提供信息和转换的,那么我撤回一些批评。从你所拥有的上下文来看,这并不明显(至少对我而言)。
  • 是的,我有一个包含 libMy_Lib.a 的目录,但我在发布之前对其进行了编辑。你是对的,那不是很明显。 :) 你的批评是建设性的 :) 谢谢
猜你喜欢
  • 2011-05-14
  • 1970-01-01
  • 1970-01-01
  • 2010-10-08
  • 1970-01-01
  • 1970-01-01
  • 2016-03-04
  • 2012-12-16
相关资源
最近更新 更多