Error when Configuring RStan C++ toolchain

sure,

Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found
> str(cppcode)
List of 5
 $ status       : logi TRUE
 $ model_cppname: chr "model2b7c5b4440e_mod"
 $ cppcode      : chr "// Code generated by Stan version 2.21.0\n\n#include <stan/model/model_header.hpp>\n\nnamespace model2b7c5b4440"| __truncated__
 $ model_name   : chr "mod"
 $ model_code   : chr "data{ real y_mean; } parameters{ real y;} model{ y ~normal(y_mean,1); }"
  ..- attr(*, "model_name2")= chr "mod"

I just cleared all objects from the workspace, then I ran the example and got:

Click the Refresh button to see progress of the chains
starting worker pid=15304 on localhost:11282 at 01:34:01.222
starting worker pid=21596 on localhost:11282 at 01:34:01.393
starting worker pid=10536 on localhost:11282 at 01:34:01.548
starting worker pid=7400 on localhost:11282 at 01:34:01.704

SAMPLING FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 0.014 seconds (Warm-up)
Chain 1:                0.01 seconds (Sampling)
Chain 1:                0.024 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 0.014 seconds (Warm-up)
Chain 2:                0.014 seconds (Sampling)
Chain 2:                0.028 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 0.008 seconds (Warm-up)
Chain 3:                0.007 seconds (Sampling)
Chain 3:                0.015 seconds (Total)
Chain 3: 

SAMPLING FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW (CHAIN 4).
Chain 4: 
Chain 4: Gradient evaluation took 0 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4: 
Chain 4: 
Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 0.007 seconds (Warm-up)
Chain 4:                0.007 seconds (Sampling)
Chain 4:                0.014 seconds (Total)
Chain 4: 
Warning message:
package 'ggplot2' was built under R version 4.0.5 

Is this the correct result? Since the output was different last time.

Yes that’s the correct result, it means that all is working fine

Hi - I have used rstan on my old machine using R 3.6.1. I’m trying to get setup on my new machine with R 4.1.3 and I’m having problems similar to those outlined above.

I get the same error message when I attempt the jsonlite install from source:

*** arch - i386
C:/rtools40/ucrt64/mingw_32/bin/gcc  -I"C:/Users/fwhiting/DOCUME~1/R/R-41~1.3/include" -DNDEBUG -Iyajl/api       -D__USE_MINGW_ANSI_STDIO   -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c base64.c -o base64.o
sh: line 1: C:/rtools40/ucrt64/mingw_32/bin/gcc: No such file or directory
make: *** [C:/Users/fwhiting/DOCUME~1/R/R-41~1.3/etc/i386/Makeconf:238: base64.o] Error 127
ERROR: compilation failed for package 'jsonlite'
* removing 'C:/Users/fwhiting/Documents/R/win-library/4.1/jsonlite'
Warning in install.packages :
  installation of package ‘jsonlite’ had non-zero exit status

And I get the following outputs for the inputs suggested by @andrjohns:

Sys.getenv(“BINPREF”)

[1] "C:/rtools40/ucrt64/mingw_$(WIN)/bin/"

Sys.getenv(“PATH”)

[1] "C:/rtools40/ucrt64/bin;C:/rtools40/usr/bin;C:\\Users\\fwhiting\\Documents\\R\\R-4.1.3\\bin\\x64;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Windows\\CCM;C:\\Program Files (x86)\\Pulse Secure\\VC142.CRT\\X64\\;C:\\Program Files (x86)\\Pulse Secure\\VC142.CRT\\X86\\;C:\\Program Files\\dotnet\\;C:\\Users\\fwhiting\\AppData\\Local\\Microsoft\\WindowsApps;"

readLines("~/.Renviron")

[1] "PATH=\"C:/rtools40/usr/bin;${PATH}\""   
[2] "PATH=\"C:/rtools40/ucrt64/bin;${PATH}\""

readLines("~/.Rprofile")

[1] "Sys.setenv(BINPREF = \"C:/rtools40/usr/mingw_$(WIN)/bin/\")"   
[2] "Sys.setenv(BINPREF = \"C:/rtools40/ucrt64/mingw_$(WIN)/bin/\")"

readLines("~/.R/Makevars.win")

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:/Users/fwhiting/Documents/.R/Makevars.win': No such file or directory

In addition,
Sys.which(“make”) returns

"C:\\rtools40\\usr\\bin\\make.exe" 

This is a fresh install on a new machine so I don’t think there will be a problem with old stan files hanging around. Thanks in advance for any help/advice!

The RStan Getting Started guide shows how to resolve this: Configuring C Toolchain for Windows ¡ stan-dev/rstan Wiki ¡ GitHub

1 Like

Ah sorry - I hadn’t seen the first ‘R 3.6’ header and had then taken the ‘repeated here for clarity’ to mean that this had already been done under the ‘rt_path’ assignment earlier.

All worked fine with

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

Thanks for your help.

To clarify, you shouldn’t have followed the R3.6 instructions at all, just the R4.0 instructions. The ‘repeated here for clarity’ refers to the RTools installation instructions from the linked CRAN website