2010-11-12 171 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中...... 我希望它會工作... :-)套接字程序..