28

I just upgraded to Mojave from High Sierra and installed Xcode plus its command line tools and additional tools. Nothing will compile from the terminal, everything says /usr/include is missing!

I checked and ALL the Dev related dirs under /usr are missing!

Any idea how to fix?

3 Answers 3

6

Add the -isysroot flag to your compile flags to automatically include the appropriate SDK header directory and avoid the need for the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package that will "in a future release, ... no longer be provided."

Examples:

-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk

or

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

You can use xcrun --show-sdk-path to find the default SDK path.

You can also use the Xcode or CommandLineTools installed /usr/bin/ versions of clang, clang++, cc, c++, gcc, g++ which are shims calling xcrun to invoke the correct tool with the currect SDK and include directories. This defaults to CommandLineTools if you have that installed.

You can switch the behavior to use Xcode by:

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

or switch back:

$ sudo xcode-select -s /Library/Developer

1
  • You can also use -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk if you just want to use the default. However, in most cases, you probably should investigate why the C compiler you're using doesn't pick up the right flags (you probably should be using clang from the SDK instead of whatever you're using).
    – ayke
    Commented May 2, 2021 at 17:39
23

You have to run another step after installing the command line tools:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Why? Apple have introduced a new build tool dance - system includes are now only kept under a specific SDK's path with Xcode 10 onwards:

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 [...] or the Command Line Tools [...] depending on which is selected using xcode-select.

[...]

The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include [emphasis added]. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

To make sure that you're using the intended version of the command line tools, run xcode-select -s <path to Xcode> or xcode select -s /Library/Developer/CommandLineTools after installing.

7
  • 4
    Nicholas Smith: How did you find this out? Commented Sep 28, 2018 at 17:27
  • 4
    I don't even have a Packages directory?!
    – nohillside
    Commented Sep 28, 2018 at 17:54
  • 2
    You might need to use sudo to get this command to work
    – stackErr
    Commented Oct 31, 2018 at 23:46
  • 1
    If you do this, you're just putting off the inevitable. Apple isn't going to provide even the compatibility package in the next release. Get used to not having /usr/include now. You don't need it.
    – Perry
    Commented Dec 18, 2018 at 22:46
  • 1
    This no longer works with Xcode 11. Commented Dec 21, 2019 at 21:28
6

The "why" is because Apple has deprecated having a /usr/include distinct from the SDK. You shouldn't rely on having it going forward.

The compilers know already to find their includes inside the SDK, so there's no real need for the /usr/include directory any more. You can find the SDK's install directory for the include files using xcrun --show-sdk-path

12
  • 5
    Is this documented anywhere?
    – mmmmmm
    Commented Sep 30, 2018 at 18:57
  • 1
    Except the fact that macOS is (was) unix04 certified.
    – lanza
    Commented Dec 9, 2018 at 8:59
  • 2
    Being conformant with the Single Unix Specification or POSIX does not require that /usr/include be present in the file system.
    – Perry
    Commented Dec 12, 2018 at 15:15
  • 1
    And yes, it's documented in the SDK documentation.
    – Perry
    Commented Dec 12, 2018 at 15:15
  • 1
    the compilers might know, but how about various configuration tools, e.g. autoconf. A lot of autoconf macros are written with an assumption that there is something meaningful in /usr, I believe. E.g. would AC_CHECK_HEADER still work? Commented Dec 15, 2018 at 11:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .