簡體   English   中英

用CygWin進行C套接字編程

[英]C Socket Programming with CygWin

嗨,我正在嘗試使用CygWin用C語言編寫一個小的服務器/客戶端程序,問題是,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環境中的其他位置?

嘗試使用-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. 在“選擇軟件包”的安裝階段。

  2. 展開DEVEL

  3. 選擇適用於C和C ++的GNU編譯器

    4.然后單擊下一步並完成安裝。

在此處輸入圖片說明

現在,嘗試使用涉及sys / socket.h的套接字程序。我希望它能起作用... :-) ..

我也有同樣的問題。 我決心審查編譯選項。

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

至少在我的小天鵝上,他們在

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

我的圖書館失語症困擾了我好幾天。 因此,請確保首先使用簡單命令配置已安裝的庫

。/配置

配置完成后,使用以下命令進行構建,安裝和檢查庫

全部 -構建庫

安裝 -安裝庫

檢查-測試庫

doc-通過doxygen生成文檔

希望能幫助到你。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM