Stan fails to compile fatal error: 'cmath' file not found 679

Hello there, I hope someone can help me.
I am using in R v. 4.4.1 on macOS 14.6.1 Chip M1

The full error report is:

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 :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 | ^~~~~~~1 error generated.make: *** [filefee91f1ef11d.o] Error 1
Error in sink(type = “output”) : invalid connection

Apparently a recent macos update moved around some of the files C++ relies on. We’ve heard some users say uninstalling and then re-installing xcode and the xcode command line tools has fixed this

1 Like

Thank you Brian,
I have re-installed Xcode, and R. Still it won’t compile the example. The error is now:

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

make would use
clang++ -arch x86_64 -std=gnu++17 
-I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   
-I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppEigen/include/unsupported"  
-I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/BH/include" 
-I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/StanHeaders/include/src/"  
-I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/StanHeaders/include/"  
-I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppParallel/include/"  
-I"/Library/Frameworks/R.framework/Versions/4.4-x86_64/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-x86_64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   
-I/opt/R/x86_64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -O3 -mtune=native -arch x86_64 -ftemplate-depth-256  -c file14ca57052400d.cpp -o file14ca57052400d.o
if test  "zfile14ca57052400d.o" != "z"; then \
    echo clang++ -arch x86_64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/x86_64/lib -o file14ca57052400d.so file14ca57052400d.o  '/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppParallel/lib/' -ltbb -L/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppParallel/lib -ltbb -ltbbmalloc   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
    clang++ -arch x86_64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/x86_64/lib -o file14ca57052400d.so file14ca57052400d.o  '/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppParallel/lib/' -ltbb -L/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppParallel/lib -ltbb -ltbbmalloc   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
  fi
  Error in compileCode(f, code, language = language, verbose = verbose) : 
  using C++ compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.4)’using C++17using SDK: ‘MacOSX15.1.sdk’In file included from <built-in>:1:
  In file included from /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:
  In file included from /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppEigen/include/Eigen/Dense:1:
  In file included from /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/RcppEigen/include/Eigen/Core:19:/Library/Frameworks/R.framework/Versions/4.4-x86_64/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: *** [file14ca57052400d.o] Error 1
Error in sink(type = "output") : invalid connection
1 Like

Was there a solution to this issue? I am encountering the same issue. I have updated R, Rstudio, uninstalled and reinstalled rstan, but still get this error message

Error in compileCode(f, code, language = language, verbose = verbose) : 
  using C++ compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.4)’
using C++17
using SDK: ‘MacOSX15.1.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: *** [filee2174fb1725.o] Error 1
Error in sink(type = "output") : invalid connection

What version of MacOS are you using?

I am having the same issue. My version of MacOS is Sanoma Version 14.7.1 (23H222)

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

Sequoia 15.0.1

@Ric @statasaurus -

Both of your error messages are reporting that you have the MacOs 15.1 SDK, but you have an older operating system version. Apple seems to not be concerned with whether or not these play nice with each other, so the advice we have been giving is either update MacOS, or downgrade Xcode to a matching version

3 Likes

Sequoia 15.1.1

I have been struggling with the same issue for a couple of days.
MacOS 15.1.1
xcode 16.1

cmdstanr::install_cmdstan() will generate the error. What can I do with this? Can someone provides some advice? Thank you

This might be because of the mismatched versions, like @WardBrian mentioned above (although in this case you Xcode is ahead of your OS).