Error when compiling brms model

Hi, sorry for not having a reproducible example ready. I am trying to fit a model using brms but am getting hit with the following error:

Compiling Stan program...
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/RICHAR~1/AppData/Local/Temp/Rtmp2J4ke3/file6860414157f6.dll':
  LoadLibrary failure:  A dynamic link library (DLL) initialization routine failed.
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found
Error in sink(type = "output") : invalid connection

Here is my session info:

R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1        stringr_1.4.0        dplyr_1.0.6          purrr_0.3.4         
 [5] readr_1.4.0          tidyr_1.1.3          tibble_3.1.2         tidyverse_1.3.1     
 [9] rstan_2.21.2         ggplot2_3.3.3        StanHeaders_2.21.0-7 fuzzyjoin_0.1.6     
[13] corrplot_0.84        brms_2.15.0          Rcpp_1.0.6          

loaded via a namespace (and not attached):
  [1] minqa_1.2.4          colorspace_2.0-0     ellipsis_0.3.2       ggridges_0.5.3      
  [5] rsconnect_0.8.18     rgdal_1.5-23         estimability_1.3     markdown_1.1        
  [9] fs_1.5.0             base64enc_0.1-3      rstudioapi_0.13      DT_0.18             
 [13] fansi_0.4.2          mvtnorm_1.1-1        lubridate_1.7.10     xml2_1.3.2          
 [17] bridgesampling_1.1-2 codetools_0.2-18     splines_4.1.0        shinythemes_1.2.0   
 [21] bayesplot_1.8.1      projpred_2.0.2       jsonlite_1.7.2       nloptr_1.2.2.2      
 [25] broom_0.7.7          dbplyr_2.1.1         shiny_1.6.0          httr_1.4.2          
 [29] compiler_4.1.0       emmeans_1.6.1        backports_1.2.1      assertthat_0.2.1    
 [33] Matrix_1.3-3         fastmap_1.1.0        cli_2.5.0            later_1.1.0.1       
 [37] htmltools_0.5.1.1    prettyunits_1.1.1    tools_4.1.0          igraph_1.2.6        
 [41] coda_0.19-4          gtable_0.3.0         glue_1.4.2           reshape2_1.4.4      
 [45] V8_3.4.0             cellranger_1.1.0     raster_3.4-5         vctrs_0.3.8         
 [49] nlme_3.1-152         crosstalk_1.1.1      ps_1.5.0             rvest_1.0.0         
 [53] lme4_1.1-26          mime_0.10            miniUI_0.1.1.1       lifecycle_1.0.0     
 [57] pacman_0.5.1         gtools_3.8.2         statmod_1.4.35       MASS_7.3-54         
 [61] zoo_1.8-9            scales_1.1.1         colourpicker_1.1.0   hms_1.1.0           
 [65] promises_1.2.0.1     Brobdingnag_1.2-6    parallel_4.1.0       inline_0.3.19       
 [69] shinystan_2.5.0      gamm4_0.2-6          curl_4.3             gridExtra_2.3       
 [73] loo_2.4.1            stringi_1.5.3        dygraphs_1.1.1.6     boot_1.3-28         
 [77] pkgbuild_1.2.0       rlang_0.4.10         pkgconfig_2.0.3      matrixStats_0.58.0  
 [81] lattice_0.20-44      rstantools_2.1.1     htmlwidgets_1.5.3    processx_3.5.2      
 [85] tidyselect_1.1.1     plyr_1.8.6           magrittr_2.0.1       R6_2.5.0            
 [89] generics_0.1.0       DBI_1.1.1            haven_2.3.1          pillar_1.6.1        
 [93] withr_2.4.2          mgcv_1.8-35          xts_0.12.1           abind_1.4-5         
 [97] sp_1.4-5             modelr_0.1.8         crayon_1.4.1         utf8_1.1.4          
[101] readxl_1.3.1         grid_4.1.0           callr_3.7.0          threejs_0.3.3       
[105] reprex_2.0.0         digest_0.6.27        xtable_1.8-4         httpuv_1.5.5        
[109] RcppParallel_5.0.3   stats4_4.1.0         munsell_0.5.0        shinyjs_2.0.0

Would appreciate any advice…

EDIT: I should maybe add, my R session is also constantly aborting with fatal error, even when I am not running anything.

Could you try using the most recent rstan from Repository for distributing (some) stan-dev R packages | r-packages ? For mostly stupid reasons, the CRAN version is a bit behind. Alternatively, you can also try installing cmdstanr and running with options(brms.backend="cmdstanr")

Hope you can get this resolved quickly.

1 Like

Thanks @martinmodrak . I managed to resolve the problem after reverting back to older builds of R (4.0.5) and rstan (2.19.3). I also deleted from my .R directory and then recreated it. Everything is currently working now.

1 Like