Error in inDL(x, as.logical(local), as.logical(now), ...) : windows 10

Since I had this problem, I uninstalled R, RStudio, RTools and deleted folders relevant to R in the Documents and AppData folder and did the following;

  1. Installed R-4.05 , rtools40 and RStudio-1.4.1106

  2. Setting up RStan

install.packages("devtools")
library("devtools")
install.packages("lme4", repos=c("http://lme4.r-forge.r-project.org/repos", getOption("repos")[["CRAN"]]))
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
#install.packages("rstanarm" , type = "source") - this had an error hence revert to line below
install.packages("rstanarm")

install.packages("tidyverse")

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, ifelse(.Platform$OS.type == "windows", "Makevars.win", "Makevars"))

if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native",
    if( grepl("^darwin", R.version$os)) "CXX14FLAGS += -arch x86_64 -ftemplate-depth-256" else
      if (.Platform$OS.type == "windows") "CXX11FLAGS=-O3 -march=corei7 -mtune=corei7" else
        "CXX14FLAGS += -fPIC",
    file = M, sep = "\n", append = TRUE)
#
M <- file.path(Sys.getenv("HOME"), ".R", ifelse(.Platform$OS.type == "windows", "Makevars.win", "Makevars"))
file.edit(M)
  1. Next tried running a sample code
library(lme4)
library(rstan)

library(rstanarm)
library(ggplot2)
library(tidyverse)
library(bayesplot)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)

Model <- stan_model(model_code = "parameters{real a;} model{a ~ normal(0,1);}",verbose = T)

This gave the following error:

TRANSLATING MODEL '094809b7474d23e9455596535b79e277' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '094809b7474d23e9455596535b79e277'.
COMPILING THE C++ CODE FOR MODEL '094809b7474d23e9455596535b79e277' NOW.
OS: x86_64, mingw32; rstan: 2.21.2; Rcpp: 1.0.6; inline: 0.3.17 
Error in cleanup_makevar(old) : 
  argument "RMU" is missing, with no default
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found
  1. After searching I did the following to overcome the error above:
remove.packages("withr", lib="~/R/win-library/4.0")
remotes::install_version("withr", "2.2.0")

Model <- stan_model(model_code = "parameters{real a;} model{a ~ normal(0,1);}",verbose = T)

Then encountered a new error:

.
.
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/SHANAK~1/AppData/Local/Temp/RtmpGMBKyC/file46e078b57720.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

Can you please help me to fix this?

When I run:
> Model <- stan_model(model_code = "parameters{real a;} model{a ~ normal(0,1);}",verbose = T)

Iā€™m getting the exact same error and warning messages as @shanakap , too.

Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/xxxx/AppData/Local/Temp/RtmpW26CVV/file33dc13ee278f.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

Anyone have a solution?
Thanks in advance.

> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

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

loaded via a namespace (and not attached):
  [1] minqa_1.2.4          colorspace_2.0-0     ellipsis_0.3.1       ggridges_0.5.3      
  [5] rsconnect_0.8.17     estimability_1.3     markdown_1.1         base64enc_0.1-3     
  [9] fs_1.5.0             rstudioapi_0.13      DT_0.18              fansi_0.4.2         
 [13] mvtnorm_1.1-1        lubridate_1.7.10     xml2_1.3.2           codetools_0.2-18    
 [17] bridgesampling_1.1-2 splines_4.0.5        knitr_1.32           shinythemes_1.2.0   
 [21] bayesplot_1.8.0      projpred_2.0.2       jsonlite_1.7.2       nloptr_1.2.2.2      
 [25] broom_0.7.6          dbplyr_2.1.1         shiny_1.6.0          compiler_4.0.5      
 [29] httr_1.4.2           emmeans_1.5.5-1      backports_1.2.1      assertthat_0.2.1    
 [33] Matrix_1.3-2         fastmap_1.1.0        cli_2.4.0            later_1.1.0.1       
 [37] prettyunits_1.1.1    htmltools_0.5.1.1    tools_4.0.5          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     vctrs_0.3.7          nlme_3.1-152        
 [49] crosstalk_1.1.1      xfun_0.22            ps_1.6.0             lme4_1.1-26         
 [53] rvest_1.0.0          mime_0.10            miniUI_0.1.1.1       lifecycle_1.0.0     
 [57] gtools_3.8.2         statmod_1.4.35       MASS_7.3-53.1        zoo_1.8-9           
 [61] scales_1.1.1         colourpicker_1.1.0   hms_1.0.0            promises_1.2.0.1    
 [65] Brobdingnag_1.2-6    parallel_4.0.5       inline_0.3.17        shinystan_2.5.0     
 [69] curl_4.3             gamm4_0.2-6          yaml_2.2.1           gridExtra_2.3       
 [73] loo_2.4.1            stringi_1.5.3        dygraphs_1.1.1.6     pkgbuild_1.2.0      
 [77] boot_1.3-27          rlang_0.4.10         pkgconfig_2.0.3      matrixStats_0.58.0  
 [81] evaluate_0.14        lattice_0.20-41      rstantools_2.1.1     htmlwidgets_1.5.3   
 [85] processx_3.5.1       tidyselect_1.1.0     plyr_1.8.6           R6_2.5.0            
 [89] generics_0.1.0       DBI_1.1.1            pillar_1.6.0         haven_2.4.0         
 [93] withr_2.4.2          mgcv_1.8-35          xts_0.12.1           abind_1.4-5         
 [97] modelr_0.1.8         crayon_1.4.1         utf8_1.2.1           rmarkdown_2.7       
[101] grid_4.0.5           readxl_1.3.1         callr_3.6.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.1.2   stats4_4.0.5         munsell_0.5.0        shinyjs_2.0.0

I fixed my problem by executing these R statements, as posted by @jrydberg https://discourse.mc-stan.org/t/r-brms-compilation-error-dll-initialization/21842:

1 Like

I ran into the same issue after updating and this helped me as well. Thanks for sharing your solution.

1 Like