How to fix a problem with a broken clang: missing stdlib.h

Viewed 9834

I have a problem with MacOS Mojave 10.14.5 and with the Xcode compiler. Precisely, I'm trying to install a package in R via Github and the compiler is complaning for a missing stdlib.h. Here is the error:

Can please someone explain me how to fix this problem?

clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -c bspline.c -o bspline.o
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
In file included from bspline.c:3:
In file included from ./pomp_internal.h:6:
/Library/Frameworks/R.framework/Resources/include/R.h:55:11: fatal error: 'stdlib.h' file not found
# include <stdlib.h> /* Not used by R itself, but widely assumed in packages */
          ^~~~~~~~~~
1 error generated.
make: *** [bspline.o] Error 1
ERROR: compilation failed for package ‘pomp’
* removing ‘/Users/Atorneri/Library/R/3.6/library/pomp’
* restoring previous ‘/Users/Atorneri/Library/R/3.6/library/pomp’
Error: Failed to install 'pomp' from GitHub:
  (converted from warning) installation of package ‘/var/folders/w7/v79h1vtd38579k18skjw2w280000gn/T//RtmpDSox3s/file3547ba46d4e/pomp_2.2.0.0.tar.gz’ had non-zero exit status
6 Answers

Running in Terminal xcode-select --install solved the problem for me.

I fixed this issue for a colleague by creating a symlink.

Here is my file system:

pi@piPro18 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
> ls -la
total 0
drwxr-xr-x  5 root  wheel  160 21 Sep 14:05 .
drwxr-xr-x  6 root  wheel  192 11 Sep 12:47 ..
drwxr-xr-x  4 root  wheel  128 30 Aug 07:47 DriverKit19.0.sdk
drwxr-xr-x  8 root  wheel  256 30 Aug 07:47 MacOSX.sdk
lrwxr-xr-x  1 root  wheel   10 21 Sep 14:02 MacOSX10.14.sdk -> MacOSX.sdk

He was missing that symlink. So we created it:

sudo ln -s MacOSX.sdk MacOSX10.14.sdk

From https://github.com/mapnik/python-mapnik/issues/167

Recently(?), Apple decided to stop naming their SDKs with versions but rather name them MacOSX.sdk and include an alias with the version name for compatibility

The one remaining mystery to me is why I have the symlink but my colleague doesn't. If anyone can explain this one, please leave a comment.

Maybe /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk not found. You can try switch xcode to xcode application.
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

I had the same issue that I solved doing:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

I also had that problem for an iOS project. The project was building for iOS 13.5 (although I set the target to 13.0). Suddenly, everything was updated in the background to 13.6, and the compiler could not find the reference to the 13.5 SDK any longer. I inspected the folder where the SDK should have been (based on the error message), and I found

drwxrwxr-x  7 root  wheel  [...] iPhoneSimulator.sdk
lrwxr-xr-x  1 root  wheel  [...] iPhoneSimulator13.6.sdk -> iPhoneSimulator.sdk

but no 13.5. Thus, following Thanh Vu I created the link

sudo ln -s iPhoneSimulator.sdk iPhoneSimulator13.5.sdk

That solved the problem. All simulators now run as 13.6.

Related