سؤال

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
هل كانت مفيدة؟

المحلول

Add #include <winsock2.h> or #include <ws2tcpip.h> on the top of includes.

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

winsock.h should be included first. And I notice that your code seems to be unixish code. On windows, closesocket is used for closing socket.

نصائح أخرى

Also, #define WIN32_LEAN_AND_MEAN before anything else. That often helps.

Also, in some cases helps this (issues with ws2tcpip identifier error):

#pragma once

#define _WIN32_WINNT 0x500

#include <winsock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "WS2_32.Lib")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top