Mac compileCode() error

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

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.

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

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.

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

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

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.)

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

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

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

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

@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:

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

Elise

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