Search code examples
c++loggingboost

Boost log linking failure after upgrade from 1.69 to 1.82


I had boost 1.69 which was working fine, I have upgraded the version to 1.82 and not changed any of the logger setup or configuration. The logger fails to link with the executable now.

I'm using boost components - log and log_setup both configure correctly and are used in target_link_libraries. The linked libraries are -

C:/vcpkg/installed/x64-windows/lib/boost_locale-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_locale-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_filesystem-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_filesystem-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_log-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_log-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_log_setup-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_log_setup-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_unit_test_framework-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_unit_test_framework-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_thread-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_thread-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_regex-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_regex-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_chrono-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_chrono-vc140-mt-gd.lib
optimizedC:/vcpkg/installed/x64-windows/lib/boost_atomic-vc140-mt.lib
debugC:/vcpkg/installed/x64-windows/debug/lib/boost_atomic-vc140-mt-gd.lib

The linking fails. Example -

set(BOOST_REQUIRED_VERSION 1.82.0)

set(BOOST_COMPONENTS locale filesystem log log_setup)

if (WITH_TESTS)
    set(BOOST_COMPONENTS ${BOOST_COMPONENTS} unit_test_framework)
endif()

find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS ${BOOST_COMPONENTS})

And a simple example -


BOOST_AUTO_TEST_CASE(LoggingTest)
{
    init();
    logging::add_common_attributes();

    using namespace logging::trivial;
    src::severity_logger< severity_level > lg;

    BOOST_LOG_SEV(lg, trace) << "A trace severity message";
    BOOST_LOG_SEV(lg, debug) << "A debug severity message";
    BOOST_LOG_SEV(lg, info) << "An informational severity message";
    BOOST_LOG_SEV(lg, warning) << "A warning severity message";
    BOOST_LOG_SEV(lg, error) << "An error severity message";
    BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
}
[build] C:\Users\Sagun Khosla\Desktop\Repos\horizon\out\install\Horizon-Tests\test\Release\LoggingTest.exe : fatal error LNK1120: 56 unresolved externals [C:\Users\Sagun Khosla\Desktop\Repos\horizon\out\build\Horizon-Tests\src\Tests\LoggingTest.vcxproj]

target_link_libraries(auth
    PUBLIC
        ${Boost_LIBRARIES}
        networking
        ${Readline_LIBRARY}
        ${LUA_LIBRARIES}
        OpenSSL::SSL
)
[build] Logger.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct boost::log::v2_mt_nt6::aux::format_description<char> __cdecl boost::log::v2_mt_nt6::aux::parse_format<char>(char const *,char const *)" (__imp_??$parse_format@D@aux@v2_mt_nt6@log@boost@@YA?AU?$format_description@D@0123@PEBD0@Z) referenced in function "public: __cdecl boost::log::v2_mt_nt6::aux::basic_format<char>::basic_format<char>(char const *)" (??0?$basic_format@D@aux@v2_mt_nt6@log@boost@@QEAA@PEBD@Z) [C:\Users\Sagun Khosla\Desktop\Repos\horizon\out\build\Horizon-Tests\src\Tests\LoggingTest.vcxproj]

Solution

  • The right fix is achieved by adding the correct definition as below -

    # Fix: error LNK2038: mismatch detected for 'boost_log_abi': value 'v2_mt_nt6' doesn't match value 'v2_mt_nt62'
    add_definitions(-D_WIN32_WINNT=0x0602)