-3
我有我的機器的主機名。我使用<unistd.h>
頭文件中的gethostname()
函數。我下載了here<unistd.h>
,但是當我試圖編譯,編譯器報告以下錯誤:關於<unistd.h>頭文件
"Cannot open include file: 'sys/cdefs.h': No such file or directory".
什麼問題?
我有我的機器的主機名。我使用<unistd.h>
頭文件中的gethostname()
函數。我下載了here<unistd.h>
,但是當我試圖編譯,編譯器報告以下錯誤:關於<unistd.h>頭文件
"Cannot open include file: 'sys/cdefs.h': No such file or directory".
什麼問題?
大概,你使用的是Windows或其他非POSIX平臺;否則,<unistd.h>
應該已經可用。
在這種情況下,你不能簡單地下載幷包含隨機的Unix頭文件,並期望它們工作;您需要使用Windows版本(在這種情況下,我認爲是<Winsock2.h>
gives that function),或者使用類似Unix的環境,例如MinGW。
您是否在Windows中嘗試此代碼?? \ – perilbrain 2012-08-06 10:56:58
您不能從隨機網站下載頭文件並期望它能正常工作。即使它編譯了,你也會得到一個鏈接錯誤。 – interjay 2012-08-06 11:01:51
@interjay heaader文件與鏈接器錯誤大多無關。在絕大多數情況下,外部頭文件不會編譯。 – 2012-08-06 11:08:28