【问题标题】:How to resolve this Linker error of BOOST Log 1 .72?如何解决 BOOST Log 1 .72 的链接器错误?
【发布时间】:2021-02-12 21:47:42
【问题描述】:

一些背景信息。

我有一个适用于两个平台/编译器的源代码库:

  • Windows 10:MinGw:x86_64-8.1.0-posix-seh-rt_v6-rev0
  • Raspberry PI 4/Linux:Raspberry-gcc8.3.0-r2

HostPc 适用于 Windows 10。

使用命令构建 BOOST Lib 后:

call bootstrap.bat mingw
call .\b2

这是构建结果:

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

:::::::::::::::::::::::\Boost_1_72_0

The following directory should be added to linker library paths:

:::::::::::::::::::::::\Boost_1_72_0\stage\lib

include 和 lib 路径是我的项目配置 (Windows/Raspberry) 的一部分。

此时可以使用 Boost-Lib 的功能。 例如:升压/asio 并且 TCP/IP 连接有效。

现在解决问题: 我想使用 BOOST Log 功能。

头文件:

#include <boost/log/trivial.hpp>

代码文件:

BOOST_LOG_TRIVIAL(info) << "This is an informational severity message";

链接器错误 (Windonws/MinGW) 看起来像:

Linking Project:executableLCB.EXE
:::::::\default/../CLogging.cpp:30: undefined reference to '__imp__ZN5boost3log9v2_mt_nt57trivial6logger3getEv'
:::::::\default/../CLogging.cpp:30: undefined reference to '__imp__ZN5boost3log9v2_mt_nt57trivial6logger3getEv'
CLogging.o: In function 'boost::log::v2_mt_nt5::record::reset()':
:::::::\default/../../Project/Boost_1_72_0/boost/log/core/record.hpp:157: undefined reference to '__imp__ZN5boost3log9v2_mt_nt511record_view11public_data7destroyEPKS3_'
CLogging.o: In function 'boost::log::v2_mt_nt5::record boost::log::v2_mt_nt5::sources::basic_composite_logger<char, boost::log::v2_mt_nt5::sources::severity_logger_mt<boost::log::v2_mt_nt5::trivial::severity_level>, boost::log::v2_mt_nt5::sources::multi_thread_model<boost::log::v2_mt_nt5::aux::light_rw_mutex>, boost::log::v2_mt_nt5::sources::features<boost::log::v2_mt_nt5::sources::severity<boost::log::v2_mt_nt5::trivial::severity_level> >
>::open_record<boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2_mt_nt5::keywords::tag::severity, boost::log::v2_mt_nt5::trivial::severity_level const> > >(boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2_mt_nt5::keywords::tag::severity, boost::log::v2_mt_nt5::trivial::severity_level const> > const&)':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/basic_logger.hpp:456: undefined reference to '__imp__ZNK5boost3log9v2_mt_nt54core19get_logging_enabledEv'
CLogging.o: In function 'boost::log::v2_mt_nt5::aux::record_pump<boost::log::v2_mt_nt5::sources::severity_logger_mt<boost::log::v2_mt_nt5::trivial::severity_level> >::record_pump(boost::log::v2_mt_nt5::sources::severity_logger_mt<boost::log::v2_mt_nt5::trivial::severity_level>&, boost::log::v2_mt_nt5::record&)':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/record_ostream.hpp:508: undefined reference to '__imp__ZN5boost3log9v2_mt_nt53aux15stream_providerIcE17allocate_compoundERNS1_6recordE'
CLogging.o: In function 'boost::log::v2_mt_nt5::aux::record_pump<boost::log::v2_mt_nt5::sources::severity_logger_mt<boost::log::v2_mt_nt5::trivial::severity_level> >::auto_release::~auto_release()':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/record_ostream.hpp:493: undefined reference to '__imp__ZN5boost3log9v2_mt_nt53aux15stream_providerIcE16release_compoundEPNS4_15stream_compoundE'
CLogging.o: In function 'boost::log::v2_mt_nt5::sources::multi_thread_model<boost::log::v2_mt_nt5::aux::light_rw_mutex>::lock_shared() const':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/threading_models.hpp:74: undefined reference to '__imp__ZN5boost3log9v2_mt_nt53aux14light_rw_mutex11lock_sharedEv'
CLogging.o: In function 'boost::log::v2_mt_nt5::sources::multi_thread_model<boost::log::v2_mt_nt5::aux::light_rw_mutex>::unlock_shared() const':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/threading_models.hpp:78: undefined reference to '__imp__ZN5boost3log9v2_mt_nt53aux14light_rw_mutex13unlock_sharedEv'
CLogging.o: In function 'boost::log::v2_mt_nt5::sources::aux::severity_level<boost::log::v2_mt_nt5::trivial::severity_level>::set_value(boost::log::v2_mt_nt5::trivial::severity_level)':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/severity_feature.hpp:135: undefined reference to '__imp__ZN5boost3log9v2_mt_nt57sources3aux18get_severity_levelEv'
CLogging.o: In function 'boost::log::v2_mt_nt5::record boost::log::v2_mt_nt5::sources::basic_logger<char, boost::log::v2_mt_nt5::sources::severity_logger_mt<boost::log::v2_mt_nt5::trivial::severity_level>, boost::log::v2_mt_nt5::sources::multi_thread_model<boost::log::v2_mt_nt5::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2_mt_nt5::keywords::tag::severity,
boost::log::v2_mt_nt5::trivial::severity_level const> > >(boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2_mt_nt5::keywords::tag::severity, boost::log::v2_mt_nt5::trivial::severity_level const> > const&)':
:::::::\default/../../Project/Boost_1_72_0/boost/log/sources/basic_logger.hpp:259: undefined reference to '__imp__ZN5boost3log9v2_mt_nt54core11open_recordERKNS1_13attribute_setE'
CLogging.o::::::::\default/../../Project/Boost_1_72_0/boost/log/core/core.hpp:308: undefined reference to '__imp__ZN5boost3log9v2_mt_nt54core16push_record_moveERNS1_6recordE'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [0.mk:182: executableLCB.EXE] Error 1

其他一些帖子解释说这涉及静态和动态链接。我尝试了不同的方法都没有成功。

linker error while linking boost log tutorial (undefined references)

  1. 问题:如何解决 windows 配置的链接器错误?

  2. 问题:如何构建和链接 Boost 静态库,以便在一个地方拥有应用程序所需的所有功能。

  3. 问题:如何构建 Boost-lib,配置 MinGW(调用 bootstrap.bat mingw)和 GCC 同时在驱动器上?

提前谢谢 石质

更新

这个错误的根本原因是,我构建了错误的库: 对于 MinGW 案例(操作系统:Windows 架构:x84_64),主机也是目标。 所以用正确的配置构建 Boost 库的命令是:

call bootstrap.bat mingw
call .\b2 toolset=gcc target-os=windows --address-model=64 --link=static --variant=debug threading=multi --with-atomic --with-chrono --with-container --with-context --with-contract --with-coroutine --with-date_time --with-exception --with-fiber --with-filesystem --with-graph --with-graph_parallel --with-headers --with-iostreams --with-locale --with-log --with-math --with-mpi --with-program_options --with-python --with-random --with-regex --with-serialization --with-stacktrace --with-system --with-test --with-thread --with-timer --with-type_erasure --with-wave

应用程序部分的链接器命令应扩展为:

..\Boost_1_72_0\stage\lib\libboost_log-mgw81-mt-x64-1_72.a
..\Boost_1_72_0\stage\lib\libboost_thread-mgw81-mt-x64-1_72.a

谢谢

【问题讨论】:

  • 显示您的链接器命令行,这肯定缺少 Boost Log 库。
  • 你说得对,在第一篇文章的错误中,-lboost_log 标志不是链接器参数的一部分。如果我将此标志放在链接器的参数列表中,则该文件不存在:..\mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_log
  • 文件夹\Boost_1_72_0\stage\lib中的Boost日志库是libboost_log-vc142-mt-gd-x32-1_72.liblibboost_log-vc142-mt-gd-x64-1_72.liblibboost_log-vc142-mt-x32-1_72.liblibboost_log-vc142-mt-x64-1_72.liblibboost_log_setup-vc142-mt-gd-x32-1_72.liblibboost_log_setup-vc142-mt-gd-x32-1_72.liblibboost_log_setup-vc142-mt-gd-x64-1_72.liblibboost_log_setup-vc142-mt-x32-1_72.liblibboost_log_setup-vc142-mt-x64-1_72.libs

标签: c++ logging boost linker


【解决方案1】:

您需要将包含 Boost 库的目录添加到链接器搜索路径:

-L/YOUR_PATH_GOES_HERE/Boost_1_72_0/stage/lib

然后链接你要使用的特定版本的库:

-lboost_log-vc142-mt-x64-1_72

【讨论】:

    【解决方案2】:

    对于 Raspberry PI 4/ Linux: Raspberry-gcc8.3.0-r2 的情况,构建失败: (主机操作系统=Windows,目标操作系统=Linux,架构:arm)

    我已在文件中插入以下行 Boost_1_72_0\libs\beast\tools\user-config.jam

    using gcc : C:\\SysGCC\\Raspberry\\bin\\arm-linux-gnueabihf-g++.exe : <ranlib>C:\\SysGCC\\Raspberry\\bin\\arm-linux-gnueabihf-ranlib.exe <archiver>C:\\SysGCC\\Raspberry\\bin\\arm-linux-gnueabihf-ar.exe ;
    

    构建 boost 库:

    call bootstrap.bat gcc
    call .\b2 target-os=linux --address-model=32 --link=static --variant=debug threading=multi --with-log --with-thread
    

    总结错误是:

    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    ./boost/thread/pthread/thread_data.hpp:58:37: error: '::sysconf' has not been declared
    ./boost/thread/pthread/thread_data.hpp:58:46: error: '_SC_PAGESIZE' was not declared in this scope
    
    ...failed gcc.link.dll bin.v2\libs\atomic\build\gcc-8.1.0\release\target-os-linux\threading-multi\visibility-hidden\libboost_atomic-gcc8-mt-x64-1_72.so.1.72.0...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\posix\object_name.o...
    ...failed gcc.link.dll bin.v2\libs\date_time\build\gcc-8.1.0\release\target-os-linux\threading-multi\visibility-hidden\libboost_date_time-gcc8-mt-x64-1_72.so.1.72.0...
    ...failed gcc.link.dll bin.v2\libs\filesystem\build\gcc-8.1.0\release\target-os-linux\threading-multi\visibility-hidden\libboost_filesystem-gcc8-mt-x64-1_72.so.1.72.0...
    ...failed gcc.link.dll bin.v2\libs\regex\build\gcc-8.1.0\release\target-os-linux\threading-multi\visibility-hidden\libboost_regex-gcc8-mt-x64-1_72.so.1.72.0...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\link-static\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\posix\object_name.o...
    ...failed gcc.link.dll bin.v2\libs\chrono\build\gcc-8.1.0\release\target-os-linux\threading-multi\visibility-hidden\libboost_chrono-gcc8-mt-x64-1_72.so.1.72.0...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\event.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\severity_level.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\link-static\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\event.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\link-static\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\severity_level.o...
    ...failed gcc.compile.c++ bin.v2\libs\thread\build\gcc-8.1.0\release\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\pthread\thread.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\link-static\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\thread_id.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\thread_id.o...
    ...failed gcc.compile.c++ bin.v2\libs\thread\build\gcc-8.1.0\release\link-static\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\pthread\thread.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\setup\init_from_settings.o...
    ...failed gcc.compile.c++ bin.v2\libs\log\build\gcc-8.1.0\release\link-static\target-os-linux\threadapi-pthread\threading-multi\visibility-hidden\setup\init_from_settings.o...
    
    

    这篇文章描述了旧 Boost 版本的过程:

    Cross-Compiling Boost on Windows for Raspberry Pi using SysGCC Toolchain and MinGW

    【讨论】:

      猜你喜欢
      • 2014-01-08
      • 2016-12-20
      • 1970-01-01
      • 2014-01-10
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 2018-03-05
      相关资源
      最近更新 更多