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

**URL:** <https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668>\
**Category:** RStan\
**Created:** [April 30, 2019, 4:22pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668 "2019-04-30T16:22:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Chan](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Ryan\_Chan](https://discourse.mc-stan.org/u/Ryan_Chan)\
**Post date:** [April 30, 2019, 4:22pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/1 "2019-04-30T16:22:41Z")

</div>

```
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
			CC=/usr/local/clang4/bin/clang
			CXX=/usr/local/clang4/bin/clang++
			CXX1X=/usr/local/clang4/bin/clang++
			CXX98=/usr/local/clang4/bin/clang++
			CXX11=/usr/local/clang4/bin/clang++
			CXX14=/usr/local/clang4/bin/clang++
			CXX17=/usr/local/clang4/bin/clang++
			LDFLAGS=-L/usr/local/clang4/lib
			# 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.

---

<div class="post-metadata">

**Author:** ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)\
**Post date:** [April 30, 2019, 5:04pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/2 "2019-04-30T17:04:30Z")

</div>

What happens if you run the following command?:

```
ls /usr/local/clang4

```

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [April 30, 2019, 9:48pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/3 "2019-04-30T21:48:01Z")

</div>

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

> [@Dealing with Mojave](https://discourse.mc-stan.org/t/dealing-with-mojave/6519):
>
> For the first time, getting rstan to work on Windows seems to be easier than getting it to work on the Mojave version Mac OS X. Mojave seems to affect different people in different ways. Here are the things I would try if rstan is not working: Make sure you have opened Xcode once via Spotlight to accept its license If that doesn’t work but you have a /Library/Developer/CommandLineTools/Packages/macOS\_SDK\_headers\_for\_macOS\_10.14. pkg, install that so it puts C++ headers back in /usr/include I…

---

<div class="post-metadata">

**Author:** ![Ryan\_Chan](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Ryan\_Chan](https://discourse.mc-stan.org/u/Ryan_Chan)\
**Post date:** [May 1, 2019, 9:48am UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/4 "2019-05-01T09:48:21Z")

</div>

I get:

```
bin	include	lib	libexec	share
```

---

<div class="post-metadata">

**Author:** ![Ryan\_Chan](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Ryan\_Chan](https://discourse.mc-stan.org/u/Ryan_Chan)\
**Post date:** [May 1, 2019, 9:54am UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/5 "2019-05-01T09:54:12Z")

</div>

Step 2 worked here thanks! I just used:

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

---

<div class="post-metadata">

**Author:** ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)\
**Post date:** [May 1, 2019, 12:22pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/6 "2019-05-01T12:22:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ryan\_Chan](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Ryan\_Chan](https://discourse.mc-stan.org/u/Ryan_Chan)\
**Post date:** [May 1, 2019, 12:48pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/7 "2019-05-01T12:48:30Z")

</div>

Do you know how I can fix this?

---

<div class="post-metadata">

**Author:** ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)\
**Post date:** [May 1, 2019, 1:10pm UTC](https://discourse.mc-stan.org/t/compilation-errors-fatal-error-stdlib-h-file-not-found/8668/8 "2019-05-01T13:10:52Z")

</div>

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.
