2

I am trying to compile a code

#include <Header1.h>
#include "Header2..h" 
#include <ctype.h>  

Header1.h includes winsock.h and Header2.h includes windows.h

I am using winsock.h instead of winsock2.h because winsock2.h was showing redefinition errors, which is a standard error, but I was not able to fix that using the solutions provided to them.

I have also tried including ws2tcpip.h, but it is giving tons of redefinition errors in winsock.h.

I am getting 12 errors in this Module

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
4

3 回答 3

3

此外,#define WIN32_LEAN_AND_MEAN 先于其他。这通常会有所帮助。

于 2014-05-19T23:13:22.943 回答
3

在包含的顶部添加#include <winsock2.h>或。#include <ws2tcpip.h>

#include <winsock2.h> 
#include <Header1.h>
#include "Header2.h"
#include <ctype.h>  

winsock.h 应该首先包含在内。而且我注意到您的代码似乎是 unixish 代码。在 windows 上,closesocket用于关闭套接字。

于 2013-06-19T06:53:09.340 回答
1

此外,在某些情况下有助于此(ws2tcpip 标识符错误的问题):

#pragma once

#define _WIN32_WINNT 0x500

#include <winsock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "WS2_32.Lib")
于 2019-09-16T13:51:30.147 回答