Modeling failed Warnings: 'C:/Users/R-34~1.3/rtools40/usr/mingw_/bin/g++' not found Errors: Multiple results for CXX14FLAGS found, something is wrong.FALSE

Dear Mr. Johns

I am currently facing the same issue as ASaeed faced half a years ago. However, when I try the following code suggested by you, I get this warning:

system(“touch foo.cpp”)
[1] 127
system(“R CMD SHLIB foo.cpp”)
Warning:
In system(cmd) : ‘make’ not found
[1] 1

So I guess that the C++ compiler is not working properly. Could you tell me how I can fix this?
Many thanks in advance! :)

Kind regards, damajo

Sorry for the delay. Yes, this indicates that R can’t find your RTools installation. Can you post the output from:

Sys.getenv("PATH")
Sys.getenv("BINPREF")
readLines("~/.Renviron")
readLines(".~/.Rprofile")
pkgbuild::check_rtools(debug = TRUE)

That will give me a better idea of where the issue could be

1 Like

No worries! I am certainly glad to receive some help since I tried many proposed solutions from the stanforum without any success. Here is the output:

Sys.getenv(“PATH”)
[1] “C:\Program Files\R-4.0.5\bin\x64;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Windows\System32\OpenSSH;C:\Users\David\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Android;C:\Windows\System32;C:\Program Files\PuTTY;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Git\cmd;C:\miketex\miktex\bin\x64;C:\Users\David\AppData\Roaming\TinyTeX\bin\win32;C:\Users\David\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64;C:\Users\David\AppData\Local\GitHubDesktop\bin;C:\Users\David\AppData\Local\Programs\Python\Python39;C:\Users\David\AppData\Local\Programs\Python\Python39\Scripts;C:\Users\David\AppData\Local\GitHubDesktop\bin”
Sys.getenv(“BINPREF”)
[1] “”
readLines("~/.Renviron")
Error in file(con, “r”) : cannot open connection
Additional: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/David/OneDrive - ZHAW/Documents/.Renviron’: No such file or directory
readLines(".~/.Rprofile")
Error in file(con, “r”) : cannot open connection.
Additional: Warning message:
In file(con, “r”) :
cannot open file ‘.~/.Rprofile’: No such file or directory
pkgbuild::check_rtools(debug = TRUE)
Found in Rtools 4.0 installation folder
[1] TRUE

There seems to be a missing connection.

It looks like the configuration for RTools4 is missing, can you try the R4.0 instructions on the RStan Getting Started page: Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub

I did and this is now the output:

Sys.getenv(“PATH”)
[1] “C:\rtools40\usr\bin;C:\Program Files\R-4.0.5\bin\x64;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\Users\David\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Android;C:\Windows\System32;C:\Program Files\PuTTY\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Git\cmd;C:\miketex\miktex\bin\x64\;C:\Users\David\AppData\Roaming\TinyTeX\bin\win32;C:\Users\David\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\;C:\Users\David\AppData\Local\GitHubDesktop\bin;C:\Users\David\AppData\Local\Programs\Python\Python39;C:\Users\David\AppData\Local\Programs\Python\Python39\Scripts;C:\Users\David\AppData\Local\GitHubDesktop\bin”
Sys.getenv(“BINPREF”)
[1] “”
readLines("~/.Renviron")
[1] “PATH=”{RTOOLS40_HOME}\\usr\\bin;{PATH}""
readLines(".~/.Rprofile")
Error in file(con, “r”) : cannot open connection.
Additional: Warning message:
In file(con, “r”) :
cannot open file ‘.~/.Rprofile’: No such file or directory
pkgbuild::check_rtools(debug = TRUE)
Found in Rtools 4.0 installation folder
[1] TRUE

And what do you get from:

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

Error in inDL(x, as.logical(local), as.logical(now), …) :
cannot load shared object ‘C:/Users/David/AppData/Local/Temp/RtmpgFkOt4/file43e07d3c3216.dll’:
LoadLibrary failure: A DLL initialisation routine has failed.
Additional: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

Try restarting R (making sure that rstan doesn’t get loaded) and reinstalling from source:

# Compile packages using all cores
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

remove.packages(c("StanHeaders","rstan"))
install.packages(c("StanHeaders","rstan"),type="source")

I did it and it worked. Then I tried your example again:

example(stan_model,package=“rstan”,run.dontrun=T)

And it did run with the following warning message:

Warning: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) : ‘C:/rtools40/usr/mingw_/bin/g++’ not found

That warning is safe to ignore, your rstan installation is ready to use

Thank you very much. Now I get a different error message:

Error in compileCode(f, code, language = language, verbose = verbose) :
from C:/Users/David/OneDrive - ZHAW/Dokumente/R/win-library/4.0/StanHeaders/include/src/stan/model/model_header.hpp:4, from file174870a7567a.cpp:14:C:/Users/David/OneDrive - ZHAW/Dokumente/R/win-library/4.0/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:13: warning: ‘void stan::math::set_zero_all_adjoints()’ defined but not used [-Wunused-function] static void set_zero_all_adjoints() { ^~~~~~~~~~~~~~~~~~~~~make: *** [C:/PROGRA~1/R-40~1.5/etc/x64/Makeconf:229: file174870a7567a.o] Error 1
Additional: 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

I am trying to implement the model b4 in section “Updated Model”:

Ah, that error is caused by a bug in that version of Stan.

To fix, you’ll have to upgrade to the experimental preview of the next version:

    remove.packages(c("StanHeaders", "rstan"))
    install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
    install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

Ah perfect, thank you very much! Now it is working.