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配置錯誤。。。