Compilation Errors: 'fatal error: 'stdlib.h' file not found'

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from file7978320d1ae5.cpp:8:
In file included from /Users/rchan/Library/R/3.5/library/StanHeaders/include/src/stan/model/model_header.hpp:4:

In file included from /Users/rchan/Library/R/3.5/library/StanHeaders/include/stan/math.hpp:4:

In file included from /Users/rchan/Library/R/3.5/library/StanHeaders/include/stan/math/rev/mat.hpp:4:

In file included from /Users/rchan/Library/R/3.5/library/StanHeaders/include/stan/math/rev/core.hpp:4:

In file included from /Users/rchan/Library/R/3.5/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:

In file included from /Users/rchan/Library/R/3.5/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:

In file included from /usr/local/clang4/bin/../include/c++/v1/cstdlib:86:

/usr/local/clang4/bin/../include/c++/v1/stdlib.h:94:15: fatal error: 'stdlib.h' file not found

#include_next <stdlib.h>

In addition: Warning message:
In system(cmd, intern = !verbose) :

Error in sink(type = "output") : invalid connection 

This is my makevars file in R:

            #The following statements are required to use the clang4 binary
			# End clang4 inclusion statements

I’ve read other threads on this and I’ve tried to use the following in the terminal

$  xcode-select --install

and got the following

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

And also tried to redownload it from the apple developers website but both failed.

What happens if you run the following command?:

ls /usr/local/clang4

One or more of the things listed here is probably applicable.

I get:

bin	include	lib	libexec	share

Step 2 worked here thanks! I just used:

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

Glad you got things running, but I do have a suspicion that you have two clang installations: a partially broken one with a clang executable in /usr/local/clang4/bin, and a working one with a clang executable in /usr/bin. You may be inadvertently using pieces from both installations, which could cause problems later.

Do you know how I can fix this?

Hard to say. I don’t know if you manually installed clang under /usr/local/clang4 yourself, or if that installation was a byproduct of installing something else.

For now, since things seem to be working, I wouldn’t uninstall anything yet, but I would keep an eye on compiler warnings and see if anything looked fishy.

1 Like