如何解決 macOS 編譯丟失 C Header 檔案
今天在 macOS 10.14 通過 brew 安裝 libgit2 之後呼叫時提示提示fatal error: 'time.h' file not found
,本以為是 brew 的問題自己去編譯問題依然。
確認了 Xcode Command Line Tools 並且再次確認了xcode-select -s /Applications/Xcode.app
之後還是這樣,就連重啟大法也不用之後,
在 Google 上檢索換了好些關鍵詞也沒找到問題出在哪,索性把關鍵詞繼續模糊放大擴大範圍,看到了 github 一個不知道是啥的專案看到有'stdio.h.h' file not found
類似的 issue 終於找到了ofollow,noindex" target="_blank">解決答案
:
關鍵原因是在於找不到 /usr/include 目錄,然而安裝 command-line tools 也不會自動幫你解決,而是需要在安裝後再手動安裝 /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 才行。
跟隨這個解決方案也附帶了解釋 :
From the latest Xcode 10 Beta 2 release notes. The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for macOS headers at the standard include path: /Applications/Xcodebeta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.1 4.sdk/usr/include For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg