A bit of background information.
I have a source code-base that should work for two platforms/compiler:
- Windows 10: MinGw: x86_64-8.1.0-posix-seh-rt_v6-rev0
- Raspberry PI 4/ Linux: Raspberry-gcc8.3.0-r2
The HostPc works with Windows 10.
After building the BOOST Lib with the commands:
call bootstrap.bat mingw
call .\b2
This is the build result:
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
The include and lib paths are part of my project configurations (Windows/Raspberry).
At this point it is possible to use the functionalities of the Boost-Lib. For example: boost/asio And a TCP/IP connection works.
Now to the problem: I want to use the BOOST Log functionality.
Header-File:
#include <boost/log/trivial.hpp>
Code-File:
BOOST_LOG_TRIVIAL(info) << "This is an informational severity message";
The Linker-Error (Windonws/MinGW)looks like:
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
Some other post explain that this deal with the static and dynamic linking. I have tried different ways without success.
linker error while linking boost log tutorial (undefined references)
Question: How to resolve this linker error for the windows configuration?
Question: How to build and link the Boost lib static, to have all the functionality that the application needs at one place.
Question: How the Boost-lib could be build, that both configuration MinGW (call bootstrap.bat mingw) and GCC are on the drive at the same time?
Thx in advance Stony
Update
The root cause of this error is, that I have build the wrong libraries: For the MinGW case (OS: Windows architecure:x84_64) the host is also the target. So the command to build the Boost library with the right configuration with all modules is:
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
Linker command of the application part should be extend with:
..\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
Thx