ubuntu - 仅在 Ubuntu 32/64 位上出现 `boost::log2_mt` 的链接错误

标签 ubuntu gcc boost linker

我有一个巨大的项目,我在其中使用 boost。 boost 将我的源代码树放在特定文件夹中,其中 gcc 32 位和 64 位的 header 和库位于单独的子文件夹中。

在 Centos 上:Linux .... SMP Tue Jun 12 09:58:12 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux没问题,每个链接都很好。

但在 Ubuntu 上相同的源代码树:Linux ... 3.2.0-48-generic #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux由于链接器错误而失败。

libtest.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::~sem_based_event()'
libtest.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::sem_based_event()'
libtest.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::set_signalled()'
libtest.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::wait()'

下面是整个链接器命令行...欢迎任何帮助!
/usr/bin/ccache  g++      -m32 -lrt -L/home/abuisson/dev/fwk/build/lin32_release -L/home/abuisson/dev/fwk/Source/../Libs/boost/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/ace/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/SafeNetRMS/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/OpenSSL/bin/out32StaticMTReleaseLinux -L/home/abuisson/dev/fwk/Source/../Libs/TinyXML/Lin32/ReleaseStaticMT -L/home/abuisson/dev/fwk/Source/../Libs/zlib/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/Curl/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/microhttpd/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/Intel/Linux32 -L/home/abuisson/dev/fwk/Source/../Libs/IPP/Lin32 -L/home/abuisson/dev/fwk/Source/../Libs/xerces/lin32 CMakeFiles/Frameworktst.dir/Framework/FrameworkTst/FrameworkTimerTst.cpp.o CMakeFiles/Frameworktst.dir/Framework/FrameworkTst/FrameworkTst.cpp.o CMakeFiles/Frameworktst.dir/Framework/FrameworkTst/WriterTst.cpp.o CMakeFiles/Frameworktst.dir/Framework/FrameworkTst/FrameworkLogTst.cpp.o  -o Frameworktst  libFramework.so libVersionInfoLib.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread -ldl -lrt libTestMediaPlugin.so libFramework.so libVersionInfoLib.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread -ldl -lrt libTestAlgorithmPlugin.so libFramework.so libVersionInfoLib.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread -ldl -lrt libTestChannel.so libFramework.so libVersionInfoLib.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread -ldl -lrt libYaffut.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread libWMCommon.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_thread-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -lpthread /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_system-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_date_time-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_regex-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_signals-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_filesystem-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_program_options-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log-gcc41-mt-1_49.a /home/abuisson/dev/fwk/Libs/boost/Lin32/libboost_log_setup-gcc41-mt-1_49.a -ldl -lrt -Wl,-rpath,/home/abuisson/dev/fwk/build/lin32_release
libFramework.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::~sem_based_event()'
libFramework.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::sem_based_event()'
libFramework.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::set_signalled()'
libFramework.so: undefined reference to `boost::log2_mt_posix::aux::sem_based_event::wait()'

最佳答案

我们也遇到了同样的问题,发现库中确实不存在符号“sem_based_event”。那么问题是为什么要包含此类“sem_based_event”的标题。

这个问题是因为我们尝试在具有 gcc 4.4 或更高版本的平台上使用使用 gcc 4.1 构建的 boost 库引起的。

基于 gcc 4.3 中引入的标志“__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4”启用/包含类 sem_based_event。所以,当我们用 4.1 版本构建 boost 库时,这个类是不包含/启用的。但是,此标志既用于定义,也用于“sem_based_event”类的声明。在具有 gcc 4.1 (CentOs5.7) 的平台上,声明也被禁用,我们没有看到任何链接器错误。但是,在 gcc 4.4 或更高版本的平台上(例如 Ubuntu 10.10),“sem_based_event”类的声明将在编译期间启用,如果我们仍然尝试将其与 4.1 构建的 boost log 库链接,它将无法找到符号,从而导致上述错误。

如何修复它:

使用正确编译版本的 boost 库,即使用与您将要使用的 gcc 版本相同的版本来编译 boost 库。

关于ubuntu - 仅在 Ubuntu 32/64 位上出现 `boost::log2_mt` 的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18744701/

相关文章:

linux - crontab 运行 wget 命令

gcc - 为什么链接库的顺序有时会导致 GCC 出错?

c++ - 在 windows 中构建 boost 的子集

c++ - weak_ptr 是如何工作的?

java - 不能通过Eclipse启动Tomcat

git - 通过 "IP"端口 22 和 client_loop : send disconnect: Broken pipe on cloning a repo from bitbucket 重置连接

ubuntu - 如何在 Ubuntu 中启用 control+alt+backspace 来杀死 X?

windows - 无法编译 nn 库 - 是否未安装 gcc?

objective-c - Xcode自定义 header 模板: ___DATE___ format

c++ - 何时调用 SSL_set_verify 与 SSL_CTX_set_verify