Cannot find stdio.h

The root reason is due to a missing /usr/include directory.

Installing command-line tools (xcode-select --install), sometimes, will not automatically add it.

The Link shows the correct way: After installing command-line tools Install the package at:

# run this in Terminal
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

After that,

you should have a directory /usr/include with header files


I had the same problem for compiling R packages, and running xcode-select --install and macOS_SDK_headers_for_macOS_10.14.pkg did not solve the problem.

I discovered that there seems to be some confusion from Apples side between macOS 10.14 and 10.15, since I'm running Mojave (10.14) with the latest xcode 11.0 (11A420a), and when clang compiles it looks for the MacOSX10.14.sdk sysroot directory in

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

but there only MacOSX10.15.sdk is present (along with other stuff). I fixed this with

pushd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ sudo ln -s MacOSX.sdk MacOSX10.14.sdk popd

Now I can install packages in RStudio again.


Try setting SDKROOT explicitly to the system SDK:

export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)

Doing it avoids the need for creating symlinks in /usr.

This error seem recurrent, for example, if you installed another compiler (e.g. gcc from brew). Setting SDKROOT became so common that it might be a good idea to add it to ~/.bash_profile.

Tags:

Macos