使用 Boost Asio 时出错

Error while using Boost Asio

每当我尝试将 < boost/asio.hpp > 包含到我的代码中时,我在 win_object_handle_service.ipp 中得到“::UnregisterWaitEx is not declared”。

目前我在 Windows 8.1.Code::Blocks 上使用 MinGW 编译器(未与 IDE 捆绑在一起)。

Boost 是在 mingw 包含文件夹之外构建的,但包含在项目设置中。

我得到的确切错误:

boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp||In member   function 'void       boost::asio::detail::win_object_handle_service::move_construct(boost::asio::deta il::win_object_handle_service::implementation_type&,  boost::asio::detail::win_object_handle_service::implementation_type&)':|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp|106|error: '::UnregisterWaitEx' has not been declared|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp||In member function 'void     boost::asio::detail::win_object_handle_service::move_assign(boost::asio::detail::win_object_handle_service::implementation_type&, boost::asio::detail::win_object_handle_service&, boost::asio::detail::win_object_handle_service::implementation_type&)':|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp|158|error: '::UnregisterWaitEx' has not been declared|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp||In member function 'void boost::asio::detail::win_object_handle_service::destroy(boost::asio::detail::win_object_handle_service::implementation_type&)':|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp|200|error: '::UnregisterWaitEx' has not been declared|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp||In member function 'boost::system::error_code boost::asio::detail::win_object_handle_service::close(boost::asio::detail::win_object_handle_service::implementation_type&, boost::system::error_code&)':|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp|251|error: '::UnregisterWaitEx' has not been declared|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp||In member function 'boost::system::error_code boost::asio::detail::win_object_handle_service::cancel(boost::asio::detail::win_object_handle_service::implementation_type&, boost::system::error_code&)':|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp|302|error: '::UnregisterWaitEx' has not been declared|
boost_1_58_0\boost\asio\detail\impl\win_object_handle_service.ipp|402|error: '::UnregisterWaitEx' has not been declared|
boost_1_58_0\boost\system\error_code.hpp|221|warning: 'boost::system::posix_category' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\system\error_code.hpp|222|warning: 'boost::system::errno_ecat' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\system\error_code.hpp|223|warning: 'boost::system::native_ecat' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\asio\error.hpp|258|warning: 'boost::asio::error::system_category' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\asio\error.hpp|260|warning: 'boost::asio::error::netdb_category' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\asio\error.hpp|262|warning: 'boost::asio::error::addrinfo_category' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\asio\error.hpp|264|warning: 'boost::asio::error::misc_category' defined but not used [-Wunused-variable]|
boost_1_58_0\boost\asio\detail\winsock_init.hpp|116|warning:    'boost::asio::detail::winsock_init_instance' defined but not used [-Wunused-variable]|

我尝试过的:

  1. 将 _WIN32_WINNT 设置为 0x0601(仅添加了一个警告)
  2. 按照 here 中的说明将 struct pollfd 添加到 winsock2.h(没有任何反应)
  3. 链接的 boost 正则表达式、系统和线程库(或至少尝试过)

提前致谢,

尼克

因此,我通过将“-D_WIN32_WINNT=0x0501 -DWINVER=0x0501”添加到两个编译器链接器选项(在 C::B 中)和#defines 来修复此错误。 猜猜我添加 _WIN32_WINNT 不知何故错误。