# Mac compileCode() error

**URL:** <https://discourse.mc-stan.org/t/mac-compilecode-error/17042>\
**Category:** Interfaces\
**Tags:** rstan\
**Created:** [July 28, 2020, 1:50am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042 "2020-07-28T01:50:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![echellwig](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@echellwig](https://discourse.mc-stan.org/u/echellwig)\
**Post date:** [July 28, 2020, 1:50am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/1 "2020-07-28T01:50:56Z")

</div>

Hello all,

I’m having problems similar to the ones windows folks were having compiling stan models after upgrading to R 4.0.2. Unfortunately none of their solutions worked for me.

Software  
macOS Catalina 10.15.5  
R 4.0.2 (2020-06-22)  
RStudio 1.2.5033  
rstan 2.21.1 (2020-07-08)  
StanHeaders 2.21.0-5 (2020-06-09)

~/.R/Makevars contents:

```
 CXX=clang++ -arch x86_64 -ftemplate-depth-256 -stdlib=libstdc++

 CXXFLAGS="-mtune=native -O3 -Wall -pedantic -Wconversion" 
 #set_by_rstan
 R_XTRA_CPPFLAGS = -I$(R_INCLUDE_DIR) #set_by_rstan
 CC=clang
 CXX=clang++ -arch x86_64 -ftemplate-depth-256

 CC=clang
 CXX=clang++ -arch x86_64 -ftemplate-depth-256

 CC=clang
 CXX=clang++ -arch x86_64 -ftemplate-depth-256

 CC=clang
 CXX=clang++ -arch x86_64 -ftemplate-depth-256

 CC=clang
 CXX=clang++ -arch x86_64 -ftemplate-depth-256

```

When I ran the code below

```
example(stan_model, run.dontrun = TRUE)

```

I get the following error

Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! In file included from :1:  
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:  
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:  
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:82:  
In file included from /Library/Developer/CommandLineTools/usr/bin/…/include/c++/v1/new:90:  
In file included from /Library/Developer/CommandLineTools/usr/bin/…/include/c++/v1/exception:81:  
In file included from /Library/Developer/CommandLineTools/usr/bin/…/include/c++/v1/cstdlib:85:  
In file included from /Library/Developer/CommandLineTools/usr/bin/…/include/c++/v1/stdlib.h:93:  
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:66:  
In file included from /Library/Developer  
In addition: Warning messages:  
1: In system2(CXX, args = ARGS) : error in running command  
2: In file.remove(c(unprocessed, processed)) :  
cannot remove file ‘/var/folders/bj/v8pg71qd5wdfm8nl9kf5qjqm0000gn/T//RtmpRRpWKB/file30c5a38b13b.stan’, reason ‘No such file or directory’

There have been quite a few of these errors reported over the past month or so and I was hoping to be able to solve it based on the previous answers, but I couldn’t get any of them to work. Thanks in advance for the help!

Elise

---

<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:** [July 28, 2020, 2:08am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/2 "2020-07-28T02:08:09Z")

</div>

This should be fixed on CRAN, although you might have to install rstan from source until binaries are rebuilt. But I don’t know why the `-arch x86_64 -ftemplate-depth-256` stuff has to be part of the compiler invocation. If that stuff really is needed, it should be part of `CXX1*FLAGS`.

---

<div class="post-metadata">

**Author:** ![echellwig](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@echellwig](https://discourse.mc-stan.org/u/echellwig)\
**Post date:** [July 28, 2020, 2:27am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/3 "2020-07-28T02:27:47Z")

</div>

When I try installing rstan from source I get the following errors at many points in the attempted installation process to the point where it says there are too many errors and it is aborting the installation ( fatal error: too many errors emitted, stopping now [-ferror-limit=])

Error type 1:

> /usr/local/include/stdint.h:2:10: error: #include nested too deeply  
> #include \<stddef.h\>

Error type 2:

> /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/resource.h:197:2: error: unknown type name ‘uint64\_t’  
> uint64\_t ri\_user\_time;  
> ^

Also I have no idea about the things the makevars file. I can try removing them if you think that would help though.

Thanks again.  
Elise

---

<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:** [July 28, 2020, 2:36am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/4 "2020-07-28T02:36:23Z")

</div>

> [@echellwig](#):
>
> /usr/local/include/stdint.h:2:10: error: #include nested too deeply

My guess is that this is caused by having something in your ~/.Rprofile or ~/.Renviron files that changes the PATH environmental variable. If you comment that out, it should work with the `clang++` in Xcode.

---

<div class="post-metadata">

**Author:** ![echellwig](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@echellwig](https://discourse.mc-stan.org/u/echellwig)\
**Post date:** [July 28, 2020, 2:52am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/5 "2020-07-28T02:52:48Z")

</div>

Both my ~/.Rprofile and ~/.Renviron files are empty. Is there any way I could look at my path from inside R to see if anything is wrong with it?

Thanks.  
Elise

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 28, 2020, 3:09am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/6 "2020-07-28T03:09:04Z")

</div>

@echellwig I’m also using Catalina and R 4.0.2 and this simple Makevars works for me:

```no-highlight
CXX14FLAGS=-O3 -march=native -mtune=native 
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256

```

I think it’s probably worth trying emptying out Makevars and starting fresh with just that. (I’m not sure if `-arch x86_64` is actually necessary but it shouldn’t hurt.)

> [@echellwig](#):
>
> Is there any way I could look at my path from inside R to see if anything is wrong with it?

I think to check the contents of the PATH environment variable from R you can do `Sys.getenv("PATH")`

---

<div class="post-metadata">

**Author:** ![echellwig](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@echellwig](https://discourse.mc-stan.org/u/echellwig)\
**Post date:** [July 28, 2020, 3:28am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/7 "2020-07-28T03:28:07Z")

</div>

Updated the Makevars file and it didn’t make the error go away, but it didn’t appear to break anything additional so that’s good. Also my path is

> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/opt/ImageMagick/bin:/usr/local/git/bin:/opt/local/bin

I’m not sure how it got that way or if it is even a problem.

Elise

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 30, 2020, 4:37am UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/8 "2020-07-30T04:37:11Z")

</div>

Sorry that’s still not working. @bgoodri any ideas here?

---

<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:** [July 30, 2020, 2:58pm UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/9 "2020-07-30T14:58:30Z")

</div>

Not really. It is picking up the wrong `clang++` and the wrong library headers somehow.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 30, 2020, 4:35pm UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/10 "2020-07-30T16:35:06Z")

</div>

@echellwig Sorry we don’t have any good ideas here. Since both @bgoodri and I are out of ideas maybe it’s worth trying our other R interface CmdStanR instead of RStan and seeing that works?

Here’s a tutorial for getting started:

> **[Getting started with CmdStanR](http://mc-stan.org/cmdstanr/articles/cmdstanr.html)**
>
> cmdstanr

---

<div class="post-metadata">

**Author:** ![echellwig](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@echellwig](https://discourse.mc-stan.org/u/echellwig)\
**Post date:** [August 1, 2020, 3:40pm UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/11 "2020-08-01T15:40:40Z")

</div>

I didn’t even know there was more than one interface! I will definitely try that. Thanks again for all your help!

Elise

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [August 1, 2020, 9:00pm UTC](https://discourse.mc-stan.org/t/mac-compilecode-error/17042/12 "2020-08-01T21:00:04Z")

</div>

> [@echellwig](#):
>
> I didn’t even know there was more than one interface!

It’s brand new. Hopefully it works for you! Definitely let us know.
