Can’t compile example stan code on M1 Pro with MacOS Sonoma

I wonder if you can help me. I have a similar (but seemingly different) problem to this issue.

Specifically, having followed the online documentation for getting started, when I run …

library(rstan)
example(stan_model, package = "rstan", run.dontrun = TRUE)

… I get these errors (at the end of a long message) …

391: 
392: // declarations
393: extern "C" {
394: SEXP file382169cc6a25( ) ;
395: }
396: 
397: // definition
398: SEXP file382169cc6a25() {
399:  return Rcpp::wrap("anon_model");
400: }

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__exception/exception_ptr.h:26:33: note: definition of 'std::exception_ptr' is not complete until the closing '}'class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {                                ^fatal error: too many errors emitted, stopping now [-ferror-limit=]20 errors generated.make: *** [file382169cc6a25.o] Error 1

For context, here are the other main details that you sought:

> devtools::session_info("rstan")
─ Session info ────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.0 (2024-04-24)
 os       macOS Sonoma 14.5
 system   aarch64, darwin20
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/London
 date     2024-05-23
 rstudio  2024.04.1+748 Chocolate Cosmos (desktop)
 pandoc   NA

─ Packages ────────────────────────────────────────────────────────────────────────────────
 package        * version    date (UTC) lib source
 abind            1.4-5      2016-07-21 [1] CRAN (R 4.4.0)
 backports        1.4.1      2021-12-13 [1] CRAN (R 4.4.0)
 BH               1.84.0-0   2024-01-10 [1] CRAN (R 4.4.0)
 callr            3.7.6      2024-03-25 [1] CRAN (R 4.4.0)
 checkmate        2.3.1      2023-12-04 [1] CRAN (R 4.4.0)
 cli              3.6.2      2023-12-11 [1] CRAN (R 4.4.0)
 colorspace       2.1-0      2023-01-23 [1] CRAN (R 4.4.0)
 desc             1.4.3      2023-12-10 [1] CRAN (R 4.4.0)
 distributional   0.4.0      2024-02-07 [1] CRAN (R 4.4.0)
 fansi            1.0.6      2023-12-08 [1] CRAN (R 4.4.0)
 farver           2.1.2      2024-05-13 [1] CRAN (R 4.4.0)
 generics         0.1.3      2022-07-05 [1] CRAN (R 4.4.0)
 ggplot2          3.5.1      2024-04-23 [1] CRAN (R 4.4.0)
 glue             1.7.0      2024-01-09 [1] CRAN (R 4.4.0)
 gridExtra        2.3        2017-09-09 [1] CRAN (R 4.4.0)
 gtable           0.3.5      2024-04-22 [1] CRAN (R 4.4.0)
 inline           0.3.19     2021-05-31 [1] CRAN (R 4.4.0)
 isoband          0.2.7      2022-12-20 [1] CRAN (R 4.4.0)
 jsonlite         1.8.8      2023-12-04 [1] CRAN (R 4.4.0)
 labeling         0.4.3      2023-08-29 [1] CRAN (R 4.4.0)
 lattice          0.22-6     2024-03-20 [1] CRAN (R 4.4.0)
 lifecycle        1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
 loo              2.7.0      2024-02-24 [1] CRAN (R 4.4.0)
 magrittr         2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
 MASS             7.3-60.2   2024-04-24 [1] local
 Matrix           1.7-0      2024-03-22 [1] CRAN (R 4.4.0)
 matrixStats      1.3.0      2024-04-11 [1] CRAN (R 4.4.0)
 mgcv             1.9-1      2023-12-21 [1] CRAN (R 4.4.0)
 munsell          0.5.1      2024-04-01 [1] CRAN (R 4.4.0)
 nlme             3.1-164    2023-11-27 [1] CRAN (R 4.4.0)
 numDeriv         2016.8-1.1 2019-06-06 [1] CRAN (R 4.4.0)
 pillar           1.9.0      2023-03-22 [1] CRAN (R 4.4.0)
 pkgbuild         1.4.4      2024-03-17 [1] CRAN (R 4.4.0)
 pkgconfig        2.0.3      2019-09-22 [1] CRAN (R 4.4.0)
 posterior        1.5.0      2023-10-31 [1] CRAN (R 4.4.0)
 processx         3.8.4      2024-03-16 [1] CRAN (R 4.4.0)
 ps               1.7.6      2024-01-18 [1] CRAN (R 4.4.0)
 QuickJSR         1.1.3      2024-01-31 [1] CRAN (R 4.4.0)
 R6               2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
 RColorBrewer     1.1-3      2022-04-03 [1] CRAN (R 4.4.0)
 Rcpp             1.0.12     2024-01-09 [1] CRAN (R 4.4.0)
 RcppEigen        0.3.4.0.0  2024-02-28 [1] CRAN (R 4.4.0)
 RcppParallel     5.1.7      2023-02-27 [1] CRAN (R 4.4.0)
 rlang            1.1.3      2024-01-10 [1] CRAN (R 4.4.0)
 rstan            2.32.6     2024-03-05 [1] CRAN (R 4.4.0)
 scales           1.3.0      2023-11-28 [1] CRAN (R 4.4.0)
 StanHeaders      2.32.8     2024-05-21 [1] CRAN (R 4.4.0)
 tensorA          0.36.2.1   2023-12-13 [1] CRAN (R 4.4.0)
 tibble           3.2.1      2023-03-20 [1] CRAN (R 4.4.0)
 utf8             1.2.4      2023-10-22 [1] CRAN (R 4.4.0)
 vctrs            0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
 viridisLite      0.4.2      2023-05-02 [1] CRAN (R 4.4.0)
 withr            3.0.0      2024-01-16 [1] CRAN (R 4.4.0)

 [1] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library

───────────────────────────────────────────────────────────────────────────────────────────

… and …

> writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX17FLAGS += -O3 -mtune=native -arch arm64 -ftemplate-depth-256

Having toiled over this for a long time, I’d really welcome any help that you could give. Many thanks.

After updating my macOS, I encountered the same issue. I’m not sure if it’s due to version updates.

After reinstalling anaconda and rstan, it seems that the problem has been resolved.

Getting the same error messages and wonder if there are any solutions. Reinstalling packages didn’t work for me. Thanks!