2010-11-12 168 views
1

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

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别处这三个头?

+0

他们不显示在'/ usr/include'下? – 2010-11-12 07:03:49

+0

是的,他们是他们应该在/ usr/include/sys,netinet下的地方......但编译器找不到它们? – LightBulb 2010-11-12 07:12:23

+0

已尝试-I/usr/include? – fazo 2010-11-12 07:27:07

回答

0

至少在我cygwim他们在

在/ usr/include/sys中和/ usr/include中/ netinet

+0

他们在我的cygwin中也有,但编译器没有找到他们? – LightBulb 2010-11-12 07:14:35

1

尝试使用-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 . 
0

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

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 

OK:

$ gcc -o echo_server.exe echo_server.c 
0

我也有同样的问题..我在谷歌上搜索了几个小时,终于找到了这个...感谢拉尔夫...

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

对于套接字命令,您必须在cyg中包含一些软件包在安装... (如果已安装尝试重新安装...)

在安装WIN:

  1. 在安装的 “选择软件包” 阶段。

  2. 展开DEVEL

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

    4.And单击下一步并完成安装。

enter image description here

现在,尝试与涉及SYS/socket.h中...... 我希望它会工作... :-)套接字程序..