在Winsock.h中获得未声明的标识符错误
Getting undeclared Identifier errors in Winsock.h
我正在尝试编译代码
#include <Header1.h>
#include "Header2..h"
#include <ctype.h>
Header1.h
包括winsock.h
, Header2.h
包括windows.h
我使用winsock.h
而不是winsock2.h
,因为winsock2.h
显示重新定义错误,这是一个标准错误,但我无法使用提供给他们的解决方案来修复。
我也试过包括ws2tcpip.h
,但它在winsock.h
中给出了大量的重新定义错误。
我在这个模块中得到12个错误
error C3861: 'close': identifier not found
error C2664: 'setsockopt' : cannot convert parameter 4 from 'timeval *' to 'const char *'
error C2065: 'socklen_t' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'optionLength'
error C2065: 'optionLength' : undeclared identifier
error C2065: 'optionLength' : undeclared identifier
error C2664: 'setsockopt' : cannot convert parameter 4 from 'int32 *' to 'const char *'
error C2065: 'MSG_WAITALL' : undeclared identifier
error C2664: 'recvfrom' : cannot convert parameter 2 from 'uint8 *' to 'char *'
error C2065: 'ERROR_END_OF_STREAM' : undeclared identifier
error C3861: 'close': identifier not found
error C3861: 'close': identifier not found
在include的顶部添加#include <winsock2.h>
或#include <ws2tcpip.h>
。
#include <winsock2.h>
#include <Header1.h>
#include "Header2.h"
#include <ctype.h>
应该首先包含winsock.h。我注意到你的代码似乎是统一的。在windows上,closesocket
用于关闭socket
另外,#在任何其他内容之前定义WIN32_LEAN_AND_MEAN。
此外,在某些情况下(ws2tcpip标识符错误的问题):
#pragma once
#define _WIN32_WINNT 0x500
#include <winsock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "WS2_32.Lib")
相关文章:
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 我的函数调用 (C++) 中的未声明标识符
- 具有继承的未声明标识符(运算符 ostream)
- 无法确定 IDE 在 C++ 中说出未声明标识符的原因
- 错误 C2065:'lO':用于声明向量值的未声明标识符?
- 可变参数模板的未声明标识符
- 动态变量上的c++MACRO未声明标识符
- 指向对象的指针的未声明标识符向量
- 简单C++程序上的多个未声明标识符
- C++类"未声明标识符"
- 计算文本文件中的整数数(使用 fin>>x 的未声明标识符)
- 编译器错误 xcode 未声明标识符 C++
- 直接 X 11 纹理 FX 文件错误 X3004 未声明标识符"input"
- GCC 未声明标识符"_asm"
- ios_base类的C++未声明标识符
- 未声明标识符SQL_SS_TABLE
- 使用arrayfire的未声明标识符
- 未声明标识符和标识符未定义是什么意思?如何修复错误
- 在 MacOS 上使用 OpenMPI C++语法时未声明标识符'MPI'