RcppEigen, cmath, and rstan installation issues

My installation is failing to compile, with an error involving RcppEigen and cmath.
I’m teaching Bayesian statistics, and I’ve successfully installed or helped my students install rstan on a variety of computers. It’s always challenging, and RcppEigen appears frequently among the villains. In particular, we’ve had more success installing brms and getting rstan as a side effect than just installing rstan directly, but maybe that’s just superstition.

My specific problem today is on a MacStudio running Sonoma, R 4.4.1, RStudio 2024.09.0+375. These are the most recent versions, since I’ve done a complete removal of R, RStudio, and my Library/Frameworks/R.framework and reinstalled (more than once). I’ve run macrtools::macos_rtools_install() at least a few times now as well.

I did have rstan working on this computer two days ago, and then it stopped working - apparently after I installed ShinyStan.

So, I do a fresh install of R. Install the brms package, then run:
example(stan_model, package = "rstan", run.dontrun = TRUE)

It fails, with details below. There’s obviously many similar threads on this forum, and I’ve tried a lot of things from those threads. I’m afraid this will be another one of those threads, but I’m truly stuck. Thanks for any help!

Here’s the beginning of the compile process:

TRANSLATING MODEL '' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'anon_model' NOW.
OS: aarch64, darwin20; rstan: 2.32.6; Rcpp: 1.0.13; inline: 0.3.19 
 >> setting environment variables: 
PKG_LIBS =  '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib/' -ltbb -L/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib -ltbb -ltbbmalloc
PKG_CPPFLAGS =   -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 

Here’s the make call:

make cmd is
  make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' CXX='$(CXX17) $(CXX17STD)' CXXFLAGS='$(CXX17FLAGS)' CXXPICFLAGS='$(CXX17PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX17LDFLAGS)' SHLIB_LD='$(SHLIB_CXX17LD)' SHLIB='file38f13224fa34.so' OBJECTS='file38f13224fa34.o'

make would use
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2   -c file38f13224fa34.cpp -o file38f13224fa34.o
if test  "zfile38f13224fa34.o" != "z"; then \
	  echo clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file38f13224fa34.so file38f13224fa34.o  '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib/' -ltbb -L/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib -ltbb -ltbbmalloc   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
	  clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file38f13224fa34.so file38f13224fa34.o  '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib/' -ltbb -L/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/lib -ltbb -ltbbmalloc   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
	fi

ERROR(s) during compilation: source code errors or compiler configuration errors!

And here’s the error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  using C++ compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.3)’using C++17using SDK: ‘MacOSX15.0.sdk’In file included from <built-in>:1:In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/Eigen/Core:19:/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal error: 'cmath' file not found  679 | #include <cmath>      |          ^~~~~~~1 error generated.make: *** [file38f13224fa34.o] Error 1
1 Like

We’ve seen a few of these reports since the release of Sequoia. It seems like Apple changed some things in XCode that have caused issues.

I believe the people who have successfully navigated this have either 1) updated their OS and/or 2) re-installed XCode.

In your case, what immediately stood out to me is

If you’re still on Sonoma (OSX 14.7), you may want to try installing an older sdk/xcode version. I think mixing a OS thats still running Sonoma and a toolchain for Sequoia is a likely culprit here

Thanks, Brian.

I upgraded to Sequoia and XCode v16 and now things are working.

Much appreciated!

2 Likes

How did you upgrade to XCode v16? I’m getting the same error and haven’t been able to work around it…

FWIW, the code runs on Sonoma 14.5, but the laptop I was using/getting the same error on is running on Sonoma 14.7

I upgraded to Sequoia, V15.0.1 and then XCode to 16.0 using the App Store.
I didn’t test in between to see if Sequoia alone was enough.

Good luck!