EasyX 与 httplib 冲突解决方法
2026-5-4
(0)
报错原因
核心冲突:两者都依赖 _WIN32_WINNT 宏。
详细过程:
httplib 在编译时会用以下代码检测你的程序支持的最低 Windows 系统版本是否在 windows10 及以上:
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00
#error
"cpp - httplib doesn't support Windows 8 or lower. Please use Windows 10 or later."
#endif
如果不是在 windows10 及以上 httplib 将会直接报错,停止编译。
而在 easyx.h 中会用以下代码指定你的程序支持的最低 Windows 系统版本:
#ifndef WINVER
#define WINVER 0x0400 // Specifies that the minimum required platform is Windows 95 and Windows NT 4.0.
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500 // Specifies that the minimum required platform is Windows 2000
#endif
#ifndef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x0410 // Specifies that the minimum required platform is Windows 98
#endif
首先编译器不会定义 _WIN32_WINNT _WIN32_WINNT 的定义是在 windows.h 的相关联的头文件里。
当你先导入 windows.h 时 httplib.h 会自动引入 WinSock2.h,而 windows.h(easyx.h 会也引入它)默认会引入旧版 winsock.h,两者互斥报错
如果你先导入了 easyx.h 那么 _WIN32_WINNT 将会检测是否被定义,如果为否那么 easyx 会定义 _WIN32_WINNT 版本号常数为 0x0500。
在后面导入 httplib.h 时检测代码会被执行,直接报错,停止编译。
如何改?
1.调整顺序:先导入 httplib.h 然后 easyx.h。
2.提前声明:先把 _WIN32_WINNT 定义为 windows 10 及以上。
3.别用了:换个老牌库吧。
添加评论
取消回复