Boost + Mingw-w64 + Boost log won't work

1.3k views Asked by At

I've got boost compiled, cmake working, and everything is close to working, yet the simplest of examples (trivial logging) fails to compile with a linker error. I really don't know what to do.

Here is my current CMake setup

FIND_PACKAGE(Boost 1.54.0 COMPONENTS log log_setup REQUIRED)
...
TARGET_LINK_LIBRARIES(cogtd ${LIBS} ${SDL2_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})

Here is the error log

C:\MingW64\mingw64\bin\g++.exe  -std=c++11 -g    -mwindows -Wl,--whole-archive CMakeFiles\cogtd.dir/objects.a -Wl,--no-whole-archive  -o cogtd.exe -Wl,--out-implib,libcogtd.dll.a -Wl,--major-image-version,0,--minor-image-version,0  C:\boost_1_54_0\stage\lib\libboost_log-mgw48-mt-d-1_54.dll C:\boost_1_54_0\stage\lib\libboost_log_setup-mgw48-mt-1_54.dll SDLHelper\libSDLHelper.a Event\libEvent.a Component\libComponent.a Error\libError.a -lmingw32 C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2main.a C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2.dll.a C:\boost_1_54_0\stage\lib\libboost_log-mgw48-mt-d-1_54.dll C:\boost_1_54_0\stage\lib\libboost_log_setup-mgw48-mt-1_54.dll -lmingw32 C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2main.a C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2.dll.a -lstdc++ -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `SDL_main':
C:\cygwin\home\Cogman\cogtd\build\src/../../src/main.cxx:53: undefined reference to `boost::log::v2s_mt_nt5::trivial::logger::get()'
C:\cygwin\home\Cogman\cogtd\build\src/../../src/main.cxx:53: undefined reference to `boost::log::v2s_mt_nt5::trivial::logger::get()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::record::reset()':
C:/boost_1_54_0/boost/log/core/record.hpp:153: undefined reference to `boost::log::v2s_mt_nt5::record_view::public_data::destroy(boost::log::v2s_mt_nt5::record_view::public_data const*)'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::record boost::log::v2s_mt_nt5::sources::basic_composite_logger<char, boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>, boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>, boost::log::v2s_mt_nt5::sources::features<boost::log::v2s_mt_nt5::sources::severity<boost::log::v2s_mt_nt5::trivial::severity_level> > >::open_record<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> const&)':
C:/boost_1_54_0/boost/log/sources/basic_logger.hpp:457: undefined reference to `boost::log::v2s_mt_nt5::core::get_logging_enabled() const'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::aux::record_pump<boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level> >::~record_pump()':
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:278: undefined reference to `boost::log::v2s_mt_nt5::aux::unhandled_exception_count()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::aux::record_pump<boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level> >::record_pump(boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>&, boost::log::v2s_mt_nt5::record&)':
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:258: undefined reference to `boost::log::v2s_mt_nt5::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_nt5::record&)'
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:259: undefined reference to `boost::log::v2s_mt_nt5::aux::unhandled_exception_count()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::aux::record_pump<boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level> >::auto_release::~auto_release()':
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:243: undefined reference to `boost::log::v2s_mt_nt5::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_nt5::aux::stream_provider<char>::stream_compound*)'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>::lock_shared() const':
C:/boost_1_54_0/boost/log/sources/threading_models.hpp:74: undefined reference to `boost::log::v2s_mt_nt5::aux::light_rw_mutex::lock_shared()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>::unlock_shared() const':
C:/boost_1_54_0/boost/log/sources/threading_models.hpp:78: undefined reference to `boost::log::v2s_mt_nt5::aux::light_rw_mutex::unlock_shared()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::sources::aux::severity_level<boost::log::v2s_mt_nt5::trivial::severity_level>::set_value(boost::log::v2s_mt_nt5::trivial::severity_level)':
C:/boost_1_54_0/boost/log/sources/severity_feature.hpp:135: undefined reference to `boost::log::v2s_mt_nt5::sources::aux::get_severity_level()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::record boost::log::v2s_mt_nt5::sources::basic_logger<char, boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>, boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> const&)':
C:/boost_1_54_0/boost/log/sources/basic_logger.hpp:260: undefined reference to `boost::log::v2s_mt_nt5::core::open_record(boost::log::v2s_mt_nt5::attribute_set const&)'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::core::push_record(boost::log::v2s_mt_nt5::record&&)':
C:/boost_1_54_0/boost/log/core/core.hpp:308: undefined reference to `boost::log::v2s_mt_nt5::core::push_record_move(boost::log::v2s_mt_nt5::record&)'
collect2.exe: error: ld returned 1 exit status
src\CMakeFiles\cogtd.dir\build.make:130: recipe for target 'src/cogtd.exe' failed
make.exe[2]: *** [src/cogtd.exe] Error 1
make.exe[2]: Leaving directory 'C:/cygwin/home/Cogman/cogtd/build'
CMakeFiles\Makefile2:94: recipe for target 'src/CMakeFiles/cogtd.dir/all' failed
make.exe[1]: *** [src/CMakeFiles/cogtd.dir/all] Error 2
make.exe[1]: Leaving directory 'C:/cygwin/home/Cogman/cogtd/build'
Makefile:118: recipe for target 'all' failed
make.exe: *** [all] Error 2

Boost is compiled to use dynamic libraries.

I'm using Boost-1.54, Mingw-w64 4.8.1 rev 5 (the x64 seh posix version) and Cmake 2.8.11 I've tried static linking to no avail.

2

There are 2 answers

0
Ebrahimi On

add this to compile command and try again

-DBOOST_LOG_USE_NATIVE_SYSLOG
0
LeMoussel On

Configuring and building the library indicate that if you want to link to the shared version, it seems you need to define BOOST_LOG_DYN_LINK or BOOST_ALL_DYN_LINK. Add this to compile command: -DBOOST_LOG_DYN_LINK