Boost :: asio winsock和winsock 2兼容性问题 [英] Boost::asio winsock and winsock 2 compatibility issue

查看:1536
本文介绍了Boost :: asio winsock和winsock 2兼容性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用windows.h,其中使用了winsock.h,我需要包括boost:assio,它使用winsock2。所以我得到许多错误,说Winsock.h已经包括。
我可以定义WIN32_LEAN_AND_MEAN。所以windows.h不会使用winsock。问题是,我需要windows.h来使用它,我只需要Asio异步定时器。我不需要它的winsock2.h。我试图搜索如何禁用其winsock2使用,我发现我可以这样做通过定义BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN之前包括boost:asio,但我仍然得到相同的错误。

My project uses windows.h in which winsock.h is used, and I need to include boost:assio which uses winsock2. So I get many errors that says Winsock.h already included. I can define WIN32_LEAN_AND_MEAN. so that windows.h wouldn't use winsock. The problem is , that I need windows.h to use it, and I just need Asio for asynchronous timers. I don't need its winsock2.h . I tried searching how to disable its winsock2 use, and I found that I could do that by defining BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN before including boost:asio, but I still get the same error.

#include <windows.h>
#define BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
#include <boost/asio.hpp>

错误

1> c:\program files\boost\boost_1_47\boost\asio\detail\socket_types.hpp(22):致命错误C1189:#error:WinSock。 h已包含

1>c:\program files\boost\boost_1_47\boost\asio\detail\socket_types.hpp(22): fatal error C1189: #error : WinSock.h has already been included


推荐答案

尝试更改订单或包含。从boost / asio.hpp开始,并在它之后放置windows.h。

Try and change the order or includes. Start with boost/asio.hpp and put windows.h after it.

通常任何代码库的编写者解决兼容性问题,但如果他们的代码是第一个满足编译器和预处理器的人。

Usually the writers of any code library solve the compatibility issues but they can do it better if their code is the first to meet the compiler and preprocessor.

ACE有一个类似的问题,包括ace / OS.h,然后再解决它。

There's a similar issue with ACE, including ace/OS.h before anything else solves it.

这篇关于Boost :: asio winsock和winsock 2兼容性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆