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

The output is still huge… I am just copying the last few lines again.

In file included from \server/userhome/students4/My Documents/R/win-library/4.0/StanHeaders/include/stan/math/rev/core.hpp:46,
from ./stan/model/model_base.hpp:5,
from …/inst/include/rstan_next/stan_fit.hpp:7,
from stan_fit.cpp:1:
\server/userhome/students4/My Documents/R/win-library/4.0/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp: At global scope:
\server/userhome/students4/My Documents/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() {
^~~~~~~~~~~~~~~~~~~~~
C:/Users/R-3.4.3/rtools40/mingw32/bin/ar -rs …/inst/lib//i386/libStanServices.a stan_fit.o stan_fit_base.o
C:\Users\R-3.4.3\rtools40\mingw32\bin\ar.exe: creating …/inst/lib//i386/libStanServices.a
no DLL was created
ERROR: compilation failed for package ‘rstan’

  • removing ‘\server/userhome/students4/My Documents/R/win-library/4.0/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

This is certainly being much trickier than usual, sorry about all this!

First, we can cut down the output a bit more by adding -Wno-unused-function to Makevars.win file, in the same way you did before.

Next, I’ll get you to remove the StanHeaders package: remove.packages("StanHeaders"), and restart R.

Let’s double check that you can compile c++ from R. Can you post the output from:

system("touch foo.cpp")
system("R CMD SHLIB foo.cpp")

system(“touch foo.cpp”)
[1] 0
system(“R CMD SHLIB foo.cpp”)
C:/Users/R-3.4.3/rtools40/mingw64/bin/g++ -std=gnu++11 -I"C:/Users/R/R-40~1.3/include" -DNDEBUG -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c foo.cpp -o foo.o
C:/Users/R-3.4.3/rtools40/mingw64/bin/g++ -std=gnu++11 -shared -s -static-libgcc -o foo.dll tmp.def foo.o -LC:/Users/R/R-40~1.3/bin/x64 -lR
[1] 0

Great! So it’s compiling C and C++ without issue, so it’s not a toolchain issue. For now, can you just install RStan regularly (not from source), and then try the example model:

install.packages("rstan")
library(rstan)
example(stan_model,run.dontrun=T)

Good news rstan and stan headers got installed with no errors. But the example gave the following error.

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  cc1plus.exe: fatal error: \server/userhome/students4/My Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directorycompilation terminated.make: *** [C:/Users/R/R-40~1.3/etc/x64/Makeconf:229: file29e05485510a.o] Error 1
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/Users/R-34~1.3/rtools40/usr/mingw_/bin/g++' not found

Alright, I think this is happening because the rstan and StanHeaders packages are installed on a networked drive.

First, double-check that the file is definitely there by running:

length(list.files("~/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/"))

It should return 215.

If that’s all fine, then you’ll need to remove rstan and StanHeaders and install them in a local directory on your computer (not on the network drive). Did you need information on how to do that?

That’s strange, because I am saving them in to the local folder I have access to in the C drive. What do you mean by a network driver? Is it the server location? I am sorry I am not tech savvy.
Here is the output from the line you gave me.

length(list.files(“~/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/”))
[1] 215

It’s because when you install a package via install.packages it installs into a folder on \server/userhome/students4/My Documents/, which is located a networked drive, not a drive on your computer. This can cause issues for RStan with accessing files

Let’s try this, first restart R. Then remove the rstan and StanHeaders packages:

remove.packages(c("rstan","StanHeaders"))

Then, install them to your local library (taken from an earlier post):

install.packages("rstan",lib="C:/Users/R/R-4.0.3/library")

Does that install without erroring?

Yes. Install happened without errors. What shall I do now?

Can you try the example model from above again?

Sadly I got the following error.
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
cc1plus.exe: fatal error: \server/userhome/students4/My Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directorycompilation terminated.make: *** [C:/Users/R/R-40~1.3/etc/x64/Makeconf:229: file5ea43a8f64e0.o] Error 1
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/Users/R-34~1.3/rtools40/usr/mingw_/bin/g++’ not found

Do you think there is a reason why it can’t locate “C:/Users/R-34~1.3/rtools40/usr/mingw_/bin/g++’ not found” ??
Unfortunately its getting late here for me. So I might retire since its late here. I shall be able to reply again tomorrow morning.

Yes, but don’t worry about it.

Alright, let’s try moving the entire package installation directory to your local drive (i.e., all R packages will get installed to a folder on your computer, rather than the network drive).

First we need to remove those RStan and StanHeaders packages:

remove.packages(c("rstan","StanHeaders"))

And restart R.

Given that we know you have permissions to the C:/Users/R folder, we’ll create a folder there which your packages will be installed into:

dir.create("C:/Users/R/win-library/4.0", recursive = T)

Next, we need to tell R to install and load R packages from this directory. We can do this by setting the R_LIBS_USER environment variable using your .Renviron file:

cat("R_LIBS_USER = \"C:/Users/R/win-library/4.0\"",
    file="~/.Renviron", append=TRUE)

And then restart R. If you look at the ‘Packages’ pane in RStudio, you should only see packages listed under ‘System Library’. Next, we’ll copy R packages from your old directory to this new one (otherwise you’ll have to re-install them all):

file.copy(from="~/R/win-library/4.0/",to="C:/Users/R/win-library/",recursive = T)

Depending on how many packages you have installed, this could take a few minutes. Then restart R again.

If all of the above ran without any errors (fingers crossed), then try to install RStan and run the example model again:

install.packages("rstan")
library(rstan)
example(stan_model, run.dontrun=T)
4 Likes

Thanks Andrjohns. I did all the steps, and after I ran the model
I got this

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

That warning is completely safe to ignore, it will be fixed in the next release. Did everything run and finish sampling?

Yes! I am super thankful!!! You have been such a great help on this, I sincerely appreciate it!!!

2 Likes

Fantastic news! Thanks for hanging in there with the debugging, and sorry that it’s been such a journey.

1 Like

Not at all, actually this has been the quickest debugging I have ever had! So I am super thankful, and you gave me insights on the problem which I had no idea about.

2 Likes

Glad it’s working now @ASaeed!

And seriously thanks to you @andrjohns for hanging in there and helping them get everything sorted out. That was quite the debugging journey!

2 Likes