0

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)

  1. Question: How to resolve this linker error for the windows configuration?

  2. Question: How to build and link the Boost lib static, to have all the functionality that the application needs at one place.

  3. 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

AndreStony
  • 87
  • 6
  • Show your linker command line, which is surely missing the Boost Log library. – John Zwinck Oct 30 '20 at 12:34
  • Youre right, in the error of the first post, the -`lboost_log` flag is not part of the linker argument. If I put this flag in the argument list of the linker, the file is not there: `..\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` – AndreStony Oct 30 '20 at 14:58
  • The Boost Log Libs in the folder `\Boost_1_72_0\stage\lib` are `libboost_log-vc142-mt-gd-x32-1_72.lib` `libboost_log-vc142-mt-gd-x64-1_72.lib` `libboost_log-vc142-mt-x32-1_72.lib` `libboost_log-vc142-mt-x64-1_72.lib` `libboost_log_setup-vc142-mt-gd-x32-1_72.lib` `libboost_log_setup-vc142-mt-gd-x64-1_72.lib` `libboost_log_setup-vc142-mt-x32-1_72.lib` `libboost_log_setup-vc142-mt-x64-1_72.lib` – AndreStony Oct 30 '20 at 15:18

2 Answers2

0

You need to add the directory containing the Boost libraries to your linker search path:

-L/YOUR_PATH_GOES_HERE/Boost_1_72_0/stage/lib

And then link the particular version of the library you want to use:

-lboost_log-vc142-mt-x64-1_72
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
0

For the case Raspberry PI 4/ Linux: Raspberry-gcc8.3.0-r2 the build failed: (Host-OS=Windows, Target-OS=Linux, architecure:arm)

I have insert the following line into the file 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 ;

Build boost Lib:

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

The summary errors is:

./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...

This post describes the procedure for an older Boost version:

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

AndreStony
  • 87
  • 6