Reputation: 652
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
Upvotes: 2
Views: 6933
Reputation: 11
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")
Upvotes: 1
Reputation: 358
Also, #define WIN32_LEAN_AND_MEAN before anything else. That often helps.
Upvotes: 3
Reputation: 7733
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.
Upvotes: 3