I'm trying to use winsock2 library, i'm using it to compile tutorial server from open62541
some code that i used and make error (from open62541.c that built from amalgamation):
#include <winsock2.h>
#include <Windows.h>
#INCLUDE <ws2tcpip.h>
int main(){
struct pollfd tmp_poll_fd;
}
i'm using mingw to compile the open62541 server, and follow the tutorial
gcc -std=c99 server.c open62541.c -lws2_32 -o server.exe
the error :
error: storage size of 'tmp_poll_fd' isn't known
struct pollfd tmp_poll_fd;
the other error also related to winsock2 library such as POLLWRNORM undeclared
i already check that winsock2.h is in the place,
and i also check the inside to winsock2.h contain struct pollfd and POLLWRNORM
i already try some change in gcc command such as :
gcc -std=c99 server.c open62541.c -libws2_32 -o server.exe
is there a way to solve this?
Disclaimer: This answer is based on my locally installed version of MinGW (8.1.0, built by MinGW-W64 project), it can be a different situation on yours.
The include file "winsock2.h" has a guard on the target Windows version:
The macro
_WIN32_WINNTis set by "_mingw.h" to 0x502, if you don't change it by other means:The value 0x502 means "Windows Server 2003" according to Microsoft's document here. If you set the macro to a value greater than or equal to 0x600 ("Windows Vista"), your compile will succeed: