|
Boost Users : |
Subject: Re: [Boost-users] Compare boost::system::error_category
From: Christopher Pisz (christopherpisz_at_[hidden])
Date: 2017-03-24 20:34:48
(MSVS Specific)
So I've edited all the target files for the public Nuget packages for all
the boost libraries I am using to look like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
<ClCompile>
<PreprocessorDefinitions>BOOST_ALL_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(MSBuildThisFileDirectory)..\..\lib\native\address-model-32\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='x64'">
<ClCompile>
<PreprocessorDefinitions>BOOST_ALL_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(MSBuildThisFileDirectory)..\..\lib\native\address-model-64\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
<Target Name="CopyBoostAtomicDll" BeforeTargets="PrepareForBuild">
<Copy
SourceFiles="$(MSBuildThisFileDirectory)..\..\lib\native\address-model-32\lib\boost_atomic-vc100-mt-1_62.dll"
DestinationFolder="$(OutDir)"
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<Copy
SourceFiles="$(MSBuildThisFileDirectory)..\..\lib\native\address-model-32\lib\boost_atomic-vc100-mt-gd-1_62.dll"
DestinationFolder="$(OutDir)"
Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
</Target>
</Project>
(General)
So, now I am dynamically linking to all boost libraries and if I use the
following code, I get the expected results. If I statically link, all the if
conditions evaluate to false. This seems like a very big problem to me and
very unexpected.
//--------------------------------------------------------------------------------------------------
std::string ClientSocketASIO::ErrorCodeToString(const
boost::system::error_code & errorCode)
{
std::ostringstream debugMsg;
debugMsg << " Error Category: " << errorCode.category().name() << ". "
<< " Error Message: " << errorCode.message() << ". ";
// IMPORTANT - These comparisons only work if you dynamically link boost
libraries
// Because boost chose to implement
boost::system::error_category::operator == by comparing addresses
// The addresses are different in one library and the other
when statically linking.
//
// We use make_error_code macro to make the correct category as well as
error code value.
// Error code value is not unique and can be duplicated in more than one
category.
if (errorCode ==
make_error_code(boost::asio::error::connection_refused))
{
debugMsg << ". Connection Refused";
}
else if (errorCode == make_error_code(boost::asio::error::eof))
{
debugMsg << ". Server has disconnected.";
}
else
{
debugMsg << ". boost::system::error_code has not been mapped to a
meaningful message.";
}
return debugMsg.str();
}
Why would the authors use address comparison for the
boost::system::error_category and leave us getting different results if we
statically link vs dynamically link?
Also, is my error_code comparison now the proper and correct way to compare
error codes?
-- View this message in context: http://boost.2283326.n4.nabble.com/Compare-boost-system-error-category-tp4692861p4692910.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net