简体   繁体   English

用CygWin进行C套接字编程

[英]C Socket Programming with CygWin

Hi I'm trying to write a little server / client program in C using CygWin, problem is, the gcc compiler in Cygwin doesn't seem to contain the standard headers assosiated with socket-programming. 嗨,我正在尝试使用CygWin用C语言编写一个小的服务器/客户端程序,问题是,Cygwin中的gcc编译器似乎不包含与套接字编程相关的标准头文件。 When trying to compile my server program, i get: 当尝试编译我的服务器程序时,我得到:

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

Are these three headers located elsewhere in the CygWin-enviorment? 这三个标头是否位于CygWin环境中的其他位置?

Try using the -I compiler command line option to specify a path to the header files. 尝试使用-I编译器命令行选项来指定头文件的路径。

My local reference states 我的当地参考资料

-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 . 

I also had same problem.. i was googling for hours and finally found this... thanks to ralph... 我也遇到了同样的问题..我经过数小时的搜寻,终于找到了这个...感谢ralph ...

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

For socket commands you have to include some of the packages in cygwin while installing... (If you have installed try reinstalling ...) 对于套接字命令,您必须在安装时在cygwin中包括某些软件包...(如果已安装,请尝试重新安装...)

During the installation : 在安装过程中:

  1. In "SELECT PACKAGES " phase of installation. 在“选择软件包”的安装阶段。

  2. Expand DEVEL 展开DEVEL

  3. select GNU compilers for c and c++ 选择适用于C和C ++的GNU编译器

    4.And click next and complete the installation. 4.然后单击下一步并完成安装。

在此处输入图片说明

NOW, try with a socket program involving sys/socket.h ... I HOPE IT WILL WORK ... :-).. 现在,尝试使用涉及sys / socket.h的套接字程序。我希望它能起作用... :-) ..

I also had the same problem. 我也有同样的问题。 I've resolved to review the compile options. 我决心审查编译选项。

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

At least on my cygwim they are in 至少在我的小天鹅上,他们在

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

I had this problem for days with the library apophenia . 我的图书馆失语症困扰了我好几天。 so make sure the libraries you've installed have first been configured with a simple command 因此,请确保首先使用简单命令配置已安装的库

./configure 。/配置

once configured use the following commands to build , Install and check the libraries 配置完成后,使用以下命令进行构建,安装和检查库

all - Builds libraries 全部 -构建库

install - installs libraries 安装 -安装库

check -tests the libraries 检查-测试库

doc - generate documentation via doxygen doc-通过doxygen生成文档

Hope it helps. 希望能帮助到你。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM