0

I am making a simple project simulating UDP protocol.

I am trying to set up a connection using winsock2.h, as I am using windows and also using Clion and cygwin.

As soon as I add the winsock2.h library, I cannot seem to compile it.

This is my simple code:

#include <stdio.h> 
#include <winsock2.h>

#pragma comment(lib,"ws2_32.lib")

int main(int argc , char *argv[])
{
    WSADATA wsa;

    printf("\nInitialising Winsock...");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
    {
        printf("Failed. Error Code : %d",WSAGetLastError());
        return 1;
    }

    printf("Initialised.");

    return 0;
}

And the compile error:

Image: https://imgur.com/ZE4PVJR

[ 50%] Building C object CMakeFiles/PKS_Project.dir/main.c.o

In file included from /usr/include/w32api/winsock2.h:56:0,
from /cygdrive/c/Users/kovac/CLionProjects/PKS_Project/main.c:2:

/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set 
and associated macros have been defined in sys/types.      This can cause 
runtime problems with W32 sockets" [-Wcpp]
 #warning "fd_set and associated macros have been defined in sys/types.  \
  ^~~~~~~

In file included from 
/cygdrive/c/Users/kovac/CLionProjects/PKS_Project/main.c:2:0:
/usr/include/w32api/winsock2.h:995:34: error: conflicting types for 
'select'
   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set 
*writefds,fd_set *exceptfds,const PTIMEVAL timeout);
                              ^~~~~~
In file included from /usr/include/sys/types.h:52:0,
             from /usr/include/stdio.h:61,
             from /cygdrive/c/Users/kovac/CLionProjects/PKS_Project/main.c:1:
/usr/include/sys/select.h:62:5: note: previous declaration of 'select' was here

 int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
     ^~~~~~

make[3]: *** [CMakeFiles/PKS_Project.dir/build.make:63:CMakeFiles/PKS_Project.dir/main.c.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/PKS_Project.dir/all]Error 2
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/PKS_Project.dir/rule]Error 2
make: *** [Makefile:118: PKS_Project] Error 2

Any help woul be appreciated, as I've tried searching and couldn't find anything and I am kinda lost in this subject.

Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.