包括Boost网络库使Windows.h函数未定义
Including Boost network libraries makes Windows.h functions undefined
我正在尝试使用boost
我的include是这样的:
#include <boost/asio.hpp>
#include <Windows.h>
我正在试着测试这个呼叫:
ShellExecute(NULL, "open", "C:/local/test.txt", NULL, NULL, SW_SHOWNORMAL);
当我编译我得到"ShellExecute是未定义的"。如果我将Windows.h
包含移动到boost包含之上,它会被编译器拾取,但我会得到大量的Winsock错误。我使用的是VS 2015。
这只发生在网络库中——在此之前我一直在使用boost文件系统,没有任何问题。
Windows.h
任何想法都会很感激!
在包含Windows.h之前需要#define WIN32_LEAN_AND_MEAN
,以防止它在Windows Sockets 1标头中拖动(参见使用Windows标头)。这些头与boost asio使用的Windows Sockets 2头冲突。
下面修复了Windows Sockets声明冲突的问题:
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <boost/asio.hpp>
注意:请记住,定义WIN32_LEAN_AND_MEAN
预处理器符号会跳过包含许多系统头文件。为了解释这一点,您需要显式地包含它们。在ShellExecute的情况下,这将是#include <Shellapi.h>
。
相关文章:
- 2个模板化类的非模板友元函数未定义引用错误
- C++:在共享对象中调用抽象基类构造函数/未定义的符号
- 获取线函数未定义错误。无法在字符串中保存可验证的内容
- 链表复制构造函数 |未定义的行为
- 尝试使用 std::函数(未定义的符号)声明模板化类状态时出现链接错误
- 专用纯虚拟模板函数(未定义引用)的另一个问题
- 可视化C++ strtoull 函数未定义
- 绑定C++中的C函数(未定义的引用)
- 函数未定义引用c++
- C++构造函数未定义的引用
- 在同一语句中调用的执行 IO 的函数:未定义或未指定
- 在参数中接受 2 个类的友元函数 - 未定义'Class'
- c++ CreateWindow()函数未定义
- 使用c++中的haskell函数:未定义引用错误
- c++模板变量函数未定义引用
- OpenGL函数未定义glow
- C/ c++未使用的内联函数未定义的引用
- 调用从不兼容类型强制转换的零数据结构的成员函数-未定义
- Cocos2d-x Box2D CContactListener构造函数未定义
- 包括Boost网络库使Windows.h函数未定义