LoginSignup
26
20

More than 1 year has passed since last update.

Xcode10 の /usr/include インストール方法 (mojave)

Last updated at Posted at 2018-11-15

はじめに注意 (追記)

Xcode10 ではワークアラウンドとして /usr/include を回復するパッケージが提供されましたが、Catalina(10.15) の Xcode11 では回復出来ません。SDK の include path の方をコンパイラに参照させましょう。

対処方

最近(mojave あたり)の macOS でよくある /usr/include がいつの間にか消える問題への対処です。ある日突然 libxml2 が include 出来なくなって焦ったりします。
Xcode10 の場合、リリースノートに書いてあるように、

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

を実行する事で /usr/include が作られます。 なお、macOS SDK のヘッダは、
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
xcode-select の設定によっては /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk です。

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

or the Command Line Tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

depending on which is selected using xcode-select.

macOS_SDK_headers_for_macOS_10.14.pkg がない場合 (2019/6/18追記)

/usr/include と一緒に /Library/Developer/CommandLineTools/Packages も丸ごと消える事があります。
その場合は Developer サイトから Command Line Tools を D/L してきて、これをインストールする事で上記フォルダと macOS_SDK_headers_for_macOS_10.14.pkg が復活します。

スクリーンショット 2019-06-18 18.33.01.png
https://developer.apple.com/download/more/

Catalina (2019/10/8追記)

macOS Mojave から Catalina にアップグレードすると /usr/include が消えて、もはや二度と復活できません。諦めて SDK の include パスを使いましょう。

xcode-select の設定次第?

本来、どちらの path を使うべきか。xcode-select -p で表示されるパスが、

  • /Applications/Xcode.app/Contents/Developer なら前者の /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
  • /Library/Developer/CommandLineTools なら後者の /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

が使われるのではと推測してます。

考察

ただ、/usr/include が欲しいのって gnu cc を使う時で、そういう人はコマンドラインツールを入れてるだろうから、本来は xcode-select で後者にパスを切り替えてでも後者一択な気がする。どうなんでしょう?

多謝

感想

突然、gcc から stdio.h や stdlib.h が見つからないと言われたら焦りますよね。stdin.h なら /usr/include が消えたとすぐ気付けるのですが、libxml2 が見つからないエラーが出るとパッケージを壊したのかなと見当違いな試行錯誤をしがちです。。
あと clang だと大丈夫だったりして少し混乱する。(macOS だと /usr/bin/gcc が gnu cc でなく clang なので尚更ややこしい。。)

今までもいつの間にか /usr/include が消える事がたびたびあり、xcode --install だったり Xcode のプレファレンス設定なりで対処してましたが。

% xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

などとなるので今回はかなり困りました。

26
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
20