C Socket Programming with CygWin

喜你入骨 提交于 2020-01-13 11:34:10

问题


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


回答1:


Try using the -I compiler command line option to specify a path to the header files.

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 . 



回答2:


I also had same problem.. i was googling for hours and finally found this... thanks to ralph...

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

During the installation :

  1. In "SELECT PACKAGES " phase of installation.

  2. Expand DEVEL

  3. select GNU compilers for c and c++

    4.And click next and complete the installation.

NOW, try with a socket program involving sys/socket.h ... I HOPE IT WILL WORK ... :-)..




回答3:


At least on my cygwim they are in

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




回答4:


I also had the same problem. I've resolved to review the compile options.

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



回答5:


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

Hope it helps. :)



来源:https://stackoverflow.com/questions/4162237/c-socket-programming-with-cygwin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!