0

我正在将 NetBeans 与 CygWin 和 winsock 一起使用,并且函数之间存在冲突(令我感到耻辱的是,我不知道混合 cygwin 和 winsock 会产生冲突)

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

它与之冲突的文件是 _fd_types.h 和 unistd.h

我一直在研究并没有找到解决我的问题的方法。我已经看到不建议将 CygWin 与 Winsock 一起使用,但为时已晚。我尝试将著名的-lws2_32(如MinGW 链接器错误:winsock中所述)放入项目 -> 属性 -> 附加选项,但它仍然不起作用。我也尝试在我的源文件中添加项目ws2_32.lib但它也不起作用。此外,当在附加选项中使用 -lws2_32 时,我不会选择放置它的位置(应该在文件源之后),所以编译行类似于:

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

欢迎任何解决方案,我希望我的问题很清楚,如果不只是告诉我,我会尽量准确。

非常感谢你:-)

4

1 回答 1

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.

于 2013-10-18T18:26:45.877 回答