0

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 :-)

jww
  • 97,681
  • 90
  • 411
  • 885
Victor
  • 907
  • 2
  • 17
  • 42
  • A simple solution could be detaching the code which works with winsock into a separate library. – Vlad Oct 18 '13 at 17:10
  • Wouldn't that still make conflicts since the functions name are the same? – Victor Oct 18 '13 at 17:11
  • Well, the separate library won't depend on Cygwin, so it doesn't need the Cygwin headers. The rest of the project doesn't depend on winsock, so it doesn't need winsock.h – Vlad Oct 18 '13 at 17:13
  • I'm not sure how to do that. Would it be something like File -> New Project -> c/c++ -> C/C++ Static Library and then copypaste the code? – Victor Oct 18 '13 at 17:18
  • Not sure about static library (you can resolve naming conflict this way, but what about link conflicts?). I'd try to make it a dynamic library (i.e. DLL). – Vlad Oct 18 '13 at 17:23
  • Okay thankyou, I'm still learning so this is a bit complicated for me right now. Copying the winsock.h should be enough? then do #include "new_winsock.h"? PS: sorry for all the questions, I feel insecure with this whole thing about winsock and cygwin – Victor Oct 18 '13 at 17:27
  • Well, just copying perhaps won't be enough: it may prevent some error messages, but it wouldn't prevent the underlying problem. (You'll need to be able to create dynamic libraries anyway, so perhaps you should invest some time into learning.) – Vlad Oct 18 '13 at 17:30
  • Okay, thankyou very much, I'll keep that solution as a last resort :-D – Victor Oct 18 '13 at 17:32
  • Doesn't sound like it applies but figured it was worth mentioning just in case as it has helped me in the past with similar conflicts: 1) I use winsock2.h in my apps instead of winsock.h, and 2) I define WIN32_LEAN_AND_MEAN in my project which leaves out a bunch of less-used things (although not FD_SET)... – mark Oct 18 '13 at 17:37
  • Thankyou mark, I tried using both and using #define WIN32_LEAN_AND_MEAN but still getting conflicts, thankyou for your answer – Victor Oct 18 '13 at 17:48

1 Answers1

0

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.

Victor
  • 907
  • 2
  • 17
  • 42