当简单地包含头文件时,我从 boost::asio 中得到一些奇怪的错误asio.hpp
,然后包含其他头文件,直到win_static_mutex.ipp
它在其中生成转换错误。
我将 MinGW 与带有 -std=gnu++11 编译器标志的 GCC 4.7 一起使用(请参阅此处为什么是 gnu++11 而不是 c++11)。该错误发生在 boost 1.49、1.50 和 1.51(当前)中。
完整的错误如下:
In file included from boost1.49/boost/asio/detail/win_static_mutex.hpp:71:0,
from boost1.49/boost/asio/detail/static_mutex.hpp:23,
from boost1.49/boost/asio/detail/impl/signal_set_service.ipp:24,
from boost1.49/boost/asio/detail/signal_set_service.hpp:210,
from boost/asio/signal_set_service.hpp:19,
from boost/asio/basic_signal_set.hpp:24,
from boost/asio.hpp:26,
from MyCode\Client.cpp:3:
boost1.49/boost/asio/detail/impl/win_static_mutex.ipp: In member function 'int boost::asio::detail::win_static_mutex::do_init()':
boost1.49/boost/asio/detail/impl/win_static_mutex.ipp:51:63: error: invalid conversion from 'const wchar_t*' to 'size_t {aka unsigned int}' [-fpermissive]
boost1.49/boost/asio/detail/impl/win_static_mutex.ipp:51:63: error: invalid conversion from 'unsigned int' to 'const wchar_t*' [-fpermissive]
boost1.49/boost/asio/detail/impl/win_static_mutex.ipp:53:10: warning: declaration of 'mutex' shadows a global declaration [-Wshadow]
正如我在开头所说的,我在代码中唯一要做的就是包含asio.hpp
标题:
#include <boost/asio.hpp>
boost 文件中的第43-53行win_static_mutex.ipp
是(我已经标记了第51行):
using namespace std; // For sprintf.
wchar_t mutex_name[128];
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
swprintf_s(mutex_name, 128,
#else // BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
swprintf(mutex_name,
#endif // BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
L"asio-58CCDC44-6264-4842-90C2-F3C545CB8AA7-%u-%p",
static_cast<unsigned int>(::GetCurrentProcessId()), this); // line 51
HANDLE mutex = ::CreateMutexW(0, TRUE, mutex_name);
现在是否有一些我必须定义的定义或任何其他编译器标志,或者是否需要直接在 boost 中更改某些内容,或者是否需要更改 MinGW 的某些内容?