Sure, sorry I should have done that from the start:
macOS Sonoma Version 14.0 (23A344)
xcode-select version 2399
I’m not sure I needed the full installation of Xcode? I didn’t gather from the quickstart of Rstan that that is a requirement, but I think you are on to something. How do I know which compiler Rstan is going to use.
I know back a version I had to remove all the rstan stuff and reinstall it for it to work. I am a version back on the M1 OS and Xcode at the moment. Once my models finishing running I’ll upgrade and see what’s going on.
Thanks @Ara_Winter, I will look into this, but unfortunately, so far it looks like most of the libraries like gfortran are for Mac OS 13 and not 14, so there might be a version issue. For security reasons, I will probably not be allowed to downgrade. I will repeat the steps in the linked thread again and see if I have any luck.
Just upgraded. So before I upgraded, I removed rstan, brms, and other packages that use rstan. Not sure that’s necessary. Quit out of R and ran the upgrade.
Clean reinstall of rstan and brms through the package manager in RStudio (really need to bail out of RStudio).
So now I am running on OS14 and Xcode version 2403 on the M1 chips. Both brms models and stan models compile and run.
Unfortunately, these steps didn’t work for me. The only difference is that I didn’t remove all the packages before upgrading, because I have already the latest OS. I guess I will repeat those steps sometime soon. In the meantime I got cmdstan working, which is strange, because if there was a compiler issue, I would assume that cmdstan would also not work.
Oh weird. Yeah last time I had errors due to the mac os and xcode neither rstan, brms, or cmdstan worked. Let dig around and see if I can recreate your error message on my machine.
Here’s the full error now. I reinstalled everything including CommandLineTools. I really don’t know what the problem is.
> brm(mpg~1,mtcars)
Compiling Stan program...
make cmd is
make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f '/Users/justinsavoie/.R/Makevars' CXX='$(CXX17) $(CXX17STD)' CXXFLAGS='$(CXX17FLAGS)' CXXPICFLAGS='$(CXX17PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX17LDFLAGS)' SHLIB_LD='$(SHLIB_CXX17LD)' SHLIB='file18ab72d229a7.so' OBJECTS='file18ab72d229a7.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.3-arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.3-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.3-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -fPIC -O3 -fPIC -c file18ab72d229a7.cpp -o file18ab72d229a7.o
if test "zfile18ab72d229a7.o" != "z"; then \
echo clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file18ab72d229a7.so file18ab72d229a7.o '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppParallel/lib/' -ltbb -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 -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -o file18ab72d229a7.so file18ab72d229a7.o '/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppParallel/lib/' -ltbb -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cstring:66:5: error: <cstring> tried including <string.h> but didn't find libc++'s <string.h> header. This usually means that your header search paths are not configured properly. The header search paths should contain the C++ Standard Library headers before any C Standard Library, and you are probably using compiler flags that make that not be the case.# error <cstring> tried including <string.h> but didn't find libc++'s <string.h> header. \ ^fatal error: too many errors emitted, stopping now [-ferror-limit=]20 errors generated.make: *** [file18ab72d229a7.o] Error 1
Error in sink(type = "output") : invalid connection
I have Sonoma 14.0 (23A344).
I have xcode-select version 2399.
Additionally:
g++ --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I found this here: âš™ D131441 [libc++] Diagnose when header search paths are set up incorrectly which says "For example, people will manually add -isystem /usr/include, which ends up messing up the layering of header search paths required by libc++ (because the C Standard Library now appears before libc++ in
the search paths). " but I still don’t know how to fix it.
At the end of the day it’s probably this: “The header search paths should contain the C++ Standard Library headers before any C Standard Library, and you are probably using compiler flags that make that not be the case.” but again; not sure.
Hi @Ara_Winter it appears that it is still intact. Unfortunately that Stan typically has these compiler issues, especially after updates, which makes it so hard to get going. Still a mystery that my cmdstan works.
Okay I got it working, but not sure what fixed it. I can tell you what I did. I simply updated all my R packages in Rstudio, by clicking on the “update” button in the library tab. I suspect that some libraries related to Stan headers or other C++ libraries (like RcppParallel) maybe helped to resolve the issue.
What I did:I removed Command Line Tools. I updated Sonoma to 14.1.1. I deleted completely Homebrew (this was radical and I’m not sure it was needed, but I didn’t really need Homebrew). I installed the latest regular (non-beta) Xcode. I had tried before with CLT only; that didn’t work. CLT 15.1 beta didn’t work for me. Actually all CLT didn’t work for me.
So, update sonoma to latest, update Xcode to latest.
I wish I could be more specific as to what worked. All I can say is that I uninstalled all things related to Rstan, then followed the steps in the Getting Started Page multiple times, downloaded Xcode and made sure that all R-libraries were up to date. It sounds a bit like “have tried restarting your computer” since these are just all the basic steps.