Subject: [Boost-bugs] [Boost C++ Libraries] #7910: MSVC-11 can't find some symbols in Boost::System static library
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-01-20 21:30:09
#7910: MSVC-11 can't find some symbols in Boost::System static library
----------------------------------------------------------------------------+
Reporter: Gene Panov | Owner: bemandawes
Type: Bugs | Status: new
Milestone: To Be Determined | Component: system
Version: Boost 1.52.0 | Severity: Showstopper
Keywords: undefined symbol boost system generic_category system_category |
----------------------------------------------------------------------------+
{{{
#ifndef BOOST_SYSTEM_ERROR_CATEGORY_DIRTY_WORKAROUND
#define BOOST_SYSTEM_ERROR_CATEGORY_DIRTY_WORKAROUND
// I have not had a chance to investigate the root cause of this problem,
// but it happens when I use boost::asio on MSVC-11 (Visual Studio 2012).
// The problem seems to be that boost::system defines
generic_error_category and system_error_category,
// but then somehow doesn't have these symbols in the libboost_system-
vc110-mt-1_52.lib library when you build boost
// with just "/b2" with and toolset=msvc-11.0
// For me the problem happened when I was trying to use boost::asio from
something I compiled with MSVC-11.0.
// I got linker errors, so it's a showstopper.
// Feel free to contact me at MyName.MyLastName_at_[hidden] for more detail.
// Now, I found that if you build boost on your machine with /b2 and then
specifically do these two steps:
// > b2 --with-system threading=multi link=static runtime-link=shared
clean
// > b2 --with-system threading=multi link=static runtime-link=shared
// then magicaly the problem goes away and you don't need this workaround
below it seems.
// But since the root cause is not clear to me, the problem may not go
away for you after the steps above.
// So, if it didn't go away for you indeed, feel free to add this piece of
source code into your application.
// Two ways to do it:
// 1. if you are adding this piece of code as an include file, uncomment
these two lines:
// #undef BOOST_SYSTEM_ERROR_CATEGORY_DIRTY_WORKAROUND
// #define BOOST_SYSTEM_ERROR_CATEGORY_DIRTY_WORKAROUND inline
// 2. but if you are adding it as a separate compilation unit (source
file), then don't uncomment anything
#if defined(_MSC_VER) && _MSC_VER >= 1700
#include <system_error> // looks like implementations of three error
categories are defined in MSVC 11 include files in 'std' namespace
#include <boost/system/error_code.hpp> // interfaces for those error
categories required by boost in 'boost' namespace, but somehow
implementations cannot be found in the library files
// glue that hooks up the implementations from MSVC11 to the interfaces
required by boost
// (this glue code is **unsafe** in case MSVC or Boost change interfaces
for these error categories, because reinterpret_cast is used,
// so a safer way to go about it would be to wrap std::error_category& as
a field of some wrapper class that inherits from
boost::system::error_category,
// but it works with these versions, because boost and std interfaces are
the same ("binary compatible"!) now and I don't yet have time to do it
properly)
namespace boost { namespace system {
error_category const& system_category() {
return reinterpret_cast<const
error_category&>(std::system_category());
}
error_category const& generic_category() {
return reinterpret_cast<const
error_category&>(std::generic_category());
}
error_category const& iostream_category() {
return reinterpret_cast<const
error_category&>(std::iostream_category());
}
}}
#endif // defined(_MSC_VER) && _MSC_VER >= 1700
#endif // BOOST_SYSTEM_ERROR_CATEGORY_DIRTY_WORKAROUND
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7910> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC