1. 程式人生 > 實用技巧 >mac下C、C++專案出現‘stdio.h’ file not found的解決方法

mac下C、C++專案出現‘stdio.h’ file not found的解決方法

mac下C、C++專案出現‘stdio.h’ file not found的解決方法

有時候更新mac系統或者專案配置之後,開啟之前的專案,發現出現莫名其妙的‘stdio.h’ file not found等標頭檔案找不到。

解決這個問題之前,我們要弄清楚開發工具是引用了系統哪個目錄的這些標頭檔案的,也就是說stdio.h標頭檔案要在哪裡開發工具才能引用到。
  
這個目錄就是/usr/local/include/
我們進入/usr/local/include/發現確實沒有stdio.h等標頭檔案。原因可能是系統更新等原因丟失了。
解決方法:
  1.安裝CommandLineTools,該開發工具SDK就含有stdio.h等基礎標頭檔案
  		安裝方法:xcode-select --install
  2.檢視stdio.h等基礎標頭檔案是否存在
  		開啟Finder,command+shift+g,輸入/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ 可以定位到標頭檔案目錄。
  3.將/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/下標頭檔案軟連線到/usr/local/include/下
  		sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
mac下大部分標頭檔案在/usr/local/include/目錄下,對應的實現庫在/usr/local/lib/目錄下

我表示最後重新建立專案,移動專案檔案過去新專案解決的,雖然標頭檔案軟連線到/usr/local/include/下了,還報cmake配置錯誤。。。