如何解决BOOST日志1.72的链接器错误



一点背景信息。

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

  • Windows 10:最小Gw: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_0stagelib

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

在这一点上,可以使用Boost Lib的功能。例如:boost/asio并且TCP/IP连接可以工作。

现在来谈谈问题:我想使用BOOST日志功能。

头文件:

#include <boost/log/trivial.hpp>

代码文件:

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

Linker错误(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

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

链接boost日志教程时出现链接器错误(未定义引用(

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

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

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

Thx提前Stony

更新

这个错误的根本原因是,我构建了错误的库:对于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_0stageliblibboost_log-mgw81-mt-x64-1_72.a
..Boost_1_72_0stageliblibboost_thread-mgw81-mt-x64-1_72.a

Thx

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

-L/YOUR_PATH_GOES_HERE/Boost_1_72_0/stage/lib

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

-lboost_log-vc142-mt-x64-1_72

对于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 ;

构建助推Lib:

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.v2libsatomicbuildgcc-8.1.0releasetarget-os-linuxthreading-multivisibility-hiddenlibboost_atomic-gcc8-mt-x64-1_72.so.1.72.0...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releasetarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenposixobject_name.o...
...failed gcc.link.dll bin.v2libsdate_timebuildgcc-8.1.0releasetarget-os-linuxthreading-multivisibility-hiddenlibboost_date_time-gcc8-mt-x64-1_72.so.1.72.0...
...failed gcc.link.dll bin.v2libsfilesystembuildgcc-8.1.0releasetarget-os-linuxthreading-multivisibility-hiddenlibboost_filesystem-gcc8-mt-x64-1_72.so.1.72.0...
...failed gcc.link.dll bin.v2libsregexbuildgcc-8.1.0releasetarget-os-linuxthreading-multivisibility-hiddenlibboost_regex-gcc8-mt-x64-1_72.so.1.72.0...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releaselink-statictarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenposixobject_name.o...
...failed gcc.link.dll bin.v2libschronobuildgcc-8.1.0releasetarget-os-linuxthreading-multivisibility-hiddenlibboost_chrono-gcc8-mt-x64-1_72.so.1.72.0...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releasetarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenevent.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releasetarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenseverity_level.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releaselink-statictarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenevent.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releaselink-statictarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenseverity_level.o...
...failed gcc.compile.c++ bin.v2libsthreadbuildgcc-8.1.0releasetarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenpthreadthread.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releaselink-statictarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenthread_id.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releasetarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenthread_id.o...
...failed gcc.compile.c++ bin.v2libsthreadbuildgcc-8.1.0releaselink-statictarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddenpthreadthread.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releasetarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddensetupinit_from_settings.o...
...failed gcc.compile.c++ bin.v2libslogbuildgcc-8.1.0releaselink-statictarget-os-linuxthreadapi-pthreadthreading-multivisibility-hiddensetupinit_from_settings.o...

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

使用SysGCC工具链和MinGW 在Windows上为Raspberry Pi进行交叉编译

最新更新