使用CygWin进行C套接字编程

嗨,我正在尝试使用CygWin在C中编写一个servlets器/客户端程序,问题是,Cygwin中的gcc编译器似乎不包含与套接字编程相关的标准头文件。 在尝试编译我的服务器程序时,我得到:

netinet/in.h: No such file or directory sys/socket.h: No such file or directory netdb.h: No such file or directory 

这三个标题是否位于CygWin-enviorment的其他位置?

尝试使用-I编译器命令行选项指定头文件的路径。

我的本地参考说明

 -I dir Add the directory dir to the list of directories to be searched for header files. Directories named by -I are searched before the standard system include directories. If the directory dir is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system headers are not defeated . 

我也有同样的问题..我谷歌搜索了几个小时,终于找到了…感谢ralph …

https://ralphexe.wordpress.com/2015/09/09/run-unix-socket-program-in-windows-using-cygwin/

对于套接字命令,你必须在安装时在cygwin中包含一些软件包…(如果已安装,请尝试重新安装…)

在安装过程中:

  1. 在“SELECT PACKAGES”安装阶段。

  2. 展开DEVEL

  3. 为c和c ++选择GNU编译器

    4.然后单击“下一步”完成安装。

在此处输入图像描述

现在,尝试使用涉及sys / socket.h的套接字程序…我希望它能工作…… 🙂 ..

至少在我的cygwim他们在

/ usr / include / sys和/ usr / include / netinet

我也有同样的问题。 我已经决定审查编译选项。

NG:

 $ gcc -mno-cygwin -o echo_server.exe echo_server.c echo_server.c:12:43: sys/socket.h: No such file or directory echo_server.c:13:24: netinet/in.h: No such file or directory 

好:

 $ gcc -o echo_server.exe echo_server.c