插座在MinGW [英] Sockets in MinGW
问题描述
我只是试图在MSYS中使用MinGW构建netcat,并意识到MinGW从来没有真正移植到Windows的所有BSD套接字的东西(例如sys / socket.h)。我知道你可以使用Windows Sockets在MinGW,但为什么他们从来没有做一个Windows端口的BSD套接字?我注意到了很多程序使用#ifdef来解决这个问题。
I was just trying to build netcat in MSYS using MinGW and realized that MinGW never really ported all of the BSD socket stuff to Windows (eg sys/socket.h). I know you can use Windows Sockets in MinGW, but why did they never make a Windows port of the BSD sockets? I noticed quite a few programs using #ifdef's to workaround the issue. Is there a Windows port of the BSD sockets somewhere that can be used instead?
下面是在MSYS中为netcat做一个make的错误:
Here are the errors when doing a make for netcat in MSYS:
gcc -DLOCALEDIR=\"\/usr/local/share/locale\" -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -Wall -c `test -f 'core.c' || echo './'`core.c
In file included from core.c:29:
netcat.h:38:24: sys/socket.h: No such file or directory
netcat.h:39:63: sys/uio.h: No such file or directory
netcat.h:41:24: netinet/in.h: No such file or directory
netcat.h:42:55: arpa/inet.h: No such file or directory
no#ifdef用于MinGW。有没有库/包我可以添加到MSYS以使一切编译没有错误?
There are no #ifdef's for MinGW. Is there a library/package I can add to MSYS to make everything compile without errors?
Note: You can download netcat here and browse the CVS repo here
推荐答案
BSD sys / socket.h 是一个POSIX头,win32 API不支持它。 MinGW头部只是重新实现本机win32头部,并不提供额外的POSIX兼容性。
BSD sys/socket.h is a POSIX header and the win32 API doesn't support it. MinGW headers are just a reimplementation of native win32 headers and don't offer additional POSIX compatibility.
如果你正在寻找sys / socket.h支持,试试GNU gnulib sys / socket.h更换或使用 Cygwin ,它在Windows上提供了POSIX兼容性包装器。
If you are looking for sys/socket.h support, try either GNU gnulib's sys/socket.h replacement or go with Cygwin, which provides a POSIX compatibility wrapper on Windows.
这篇关于插座在MinGW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!