Opened 6 years ago

Last modified 6 years ago

#12974 new Bugs

Log and Asio without defined _WIN32_WINNT

Reported by: sobolevsv@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.64.0 Severity: Problem
Keywords: Win10 VC14 Cc: sobolevsv@…

Description

platform: Win10, VC14, boost 1.64

Using Log and Asio simultaneously cause link errors depending on order of includes.

if _WIN32_WINNT not defined and there are several translation units, most of it use only Log and some use both Log and Asio I get link error

if Log includes come first followed by Asio, building complete successfull
for example

#include <boost/log/common.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/asio.hpp>

but if Asio include comes before Log includes
for example

#include <boost/asio.hpp>
#include <boost/log/common.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>

I get link error: LNK2038: mismatch detected for 'boost_log_abi': value 'v2s_mt_nt5' doesn't match value 'v2s_mt_nt6' in gtclient.obj

this message generated by #pragma detect_mismatch in boost\log\detail\config.hpp :

#if defined(BOOST_LOG_HAS_PRAGMA_DETECT_MISMATCH)
#pragma detect_mismatch("boost_log_abi", BOOST_PP_STRINGIZE(BOOST_LOG_VERSION_NAMESPACE))
#endif

it happend becase Log and Asio use different macros to define target Windows version.

Log use BOOST_USE_WINAPI_VERSION
but Asio use _WIN32_WINNT

in \boost\asio\detail\config.hpp
Asio checks if _WIN32_WINNT defined. if not, it defines it

#  define _WIN32_WINNT 0x0501

BOOST_USE_WINAPI_VERSION defined in boost\detail\winapi\config.hpp

it depends on _WIN32_WINNT and _MSC_VER

#if !defined(BOOST_USE_WINAPI_VERSION)
#if defined(_WIN32_WINNT)
#define BOOST_USE_WINAPI_VERSION _WIN32_WINNT
#elif defined(WINVER)
#define BOOST_USE_WINAPI_VERSION WINVER
#else
// By default use Windows Vista API on compilers that support it and XP on the others
#if (defined(_MSC_VER) && _MSC_VER < 1500) || defined(BOOST_WINAPI_IS_MINGW)
#define BOOST_USE_WINAPI_VERSION BOOST_WINAPI_VERSION_WINXP
#else
#define BOOST_USE_WINAPI_VERSION BOOST_WINAPI_VERSION_WIN6
#endif
#endif
#endif

I think this error appeared in boost 1.60 when Log started using BOOST_USE_WINAPI_VERSION http://www.boost.org/users/history/version_1_60_0.html

if I define _WIN32_WINNT=0x0A00 in compiler option, there are no link error with any includes ordering.

Change History (2)

comment:1 by anonymous, 6 years ago

Component: Nonelog
Owner: set to Andrey Semashev

comment:2 by Andrey Semashev, 6 years ago

Component: logasio
Owner: changed from Andrey Semashev to chris_kohlhoff

I don't think this is going to be fixed unless Boost.ASIO is modified to either (a) use Boost.WinAPI or (b) default to the same target Windows version as Boost.WinAPI. My personal preference would be (a) for Boost.ASIO and any other Boost libraries, so I'm reassigning the ticket.

As for the immediate problem solution, as you've already discovered, the solution is to manually configure the target Windows version.

Note: See TracTickets for help on using tickets.