VS-2019 的编译错误
Compilation errors with VS-2019
下面的代码无法编译。我收到两个错误:
_TCHAR* pStrAddress;
... some stuff here...
IN_ADDR sa;
InetPton(AF_INET, pStrAddress, &sa);
*pIP = sa.S_un.S_addr;
1) IN_ADDR --> 错误 C2065: 'AF_INET': 未声明的标识符
2) InetPton(...) --> C3861:'InetPton':未找到标识符
我的配置如下:
- VS-2019 专业版
- Windows SDK 10.0.18362.0(最新版本 2019 年 9 月 26 日)
- 当我按 F12(转到定义)时,以下文件在编辑器中打开 (C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared\inaddr。 h 和 C:\Program Files (x86)\Windows Kits\Include.0.18362.0\um\WS2tcpip.h).
- 项目设置 "C/C++ | General | Additional include directories" 选中了 "Inherit from parent or project default" 复选框。
- Ws2_32.lib 出现在 "linker | Additional dependencies" 中(但我的问题不是关于 link 问题,或者还没有)
- 我的程序使用 unicode 并且 InetPton(...) 扩展为 InetPtonW,这是正确的。
继续,从编辑器中,可以访问符号,但 preprosessor/compiler 似乎没有相同的路径。显然我遗漏了一些最可能显而易见的东西。
非常感谢您的帮助。
谢谢!
找到了!
我创建了一个小项目,仅以 post 感兴趣的代码作为代码示例,一切都编译正常。所以,首先必须有一些显而易见的事情。然后它击中了我!:预编译头不是第一个include。
感谢大家的帮助!
不好代码:
#include <windows.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include "pch.h" <-- this must be the first include!!!!!!
好代码:
#include "pch.h" <-- ok, happy compiler and developer ;)
#include <windows.h>
#include <ws2tcpip.h>
#include <stdlib.h>
下面的代码无法编译。我收到两个错误:
_TCHAR* pStrAddress;
... some stuff here...
IN_ADDR sa;
InetPton(AF_INET, pStrAddress, &sa);
*pIP = sa.S_un.S_addr;
1) IN_ADDR --> 错误 C2065: 'AF_INET': 未声明的标识符
2) InetPton(...) --> C3861:'InetPton':未找到标识符
我的配置如下:
- VS-2019 专业版
- Windows SDK 10.0.18362.0(最新版本 2019 年 9 月 26 日)
- 当我按 F12(转到定义)时,以下文件在编辑器中打开 (C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared\inaddr。 h 和 C:\Program Files (x86)\Windows Kits\Include.0.18362.0\um\WS2tcpip.h).
- 项目设置 "C/C++ | General | Additional include directories" 选中了 "Inherit from parent or project default" 复选框。
- Ws2_32.lib 出现在 "linker | Additional dependencies" 中(但我的问题不是关于 link 问题,或者还没有)
- 我的程序使用 unicode 并且 InetPton(...) 扩展为 InetPtonW,这是正确的。
继续,从编辑器中,可以访问符号,但 preprosessor/compiler 似乎没有相同的路径。显然我遗漏了一些最可能显而易见的东西。 非常感谢您的帮助。
谢谢!
找到了! 我创建了一个小项目,仅以 post 感兴趣的代码作为代码示例,一切都编译正常。所以,首先必须有一些显而易见的事情。然后它击中了我!:预编译头不是第一个include。
感谢大家的帮助!
不好代码:
#include <windows.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include "pch.h" <-- this must be the first include!!!!!!
好代码:
#include "pch.h" <-- ok, happy compiler and developer ;)
#include <windows.h>
#include <ws2tcpip.h>
#include <stdlib.h>