Search code examples
c++gcccygwinwinsockconflict

Conflict Cygwin with winsock.h


I'm using NetBeans with CygWin and winsock and there is a conflict between functions (much to my disgrace I didn't know that mixing cygwin and winsock made conflicts)

In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/winsock.h:36:0,from main.cpp:10:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../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"
In file included from main.cpp:10:0:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/winsock.h:309:68:
error: declaration of C function ‘int gethostname(char*, int)’ conflicts with
/usr/include/sys/unistd.h:238:6: error: previous declaration ‘int gethostname(char*, size_t)’ here

The files it gets conflicts with are _fd_types.h and unistd.h

I've been researching and found no solutions to my problem. I have seen that its not advised to use CygWin with Winsock, but it's too late. I've tried to put in project -> properties -> additional options the famous -lws2_32 (as said in MinGW linker error: winsock) but it still doesn't work. I have also tried adding the item ws2_32.lib in my source files but it didn't work either. Also, when using -lws2_32 in the additional options won't let me choose where to put it (should be after file source), so the compilation line goes something like:

g++ -lws2_32 -c -g -lws2_32 -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d \
-o build/Debug/Cygwin_4.x-Windows/main.o main.cpp

ANY solution is welcome, I hope my problem is clear, if not just tell me and I'll try to be more accurate.

Thank you very much in advance :-)


Solution

  • I managed to answer it! What I did was right click on project -> properties -> linker -> Additional options and write -lws2_32 there. What I was doing before was project -> properties -> c++ compiler -> additional options and write -lws2_32 there.