Stan won't compile - getting an error message 127

Hi there, I’ve installed Stan and I get the following message when I run a test.

Error in compileCode(f, code, language = language, verbose = verbose) : 
  sh: line 1: C:/rtools40/usr/mingw_64/bin/g++: No such file or directorymake: *** [C:/PROGRA~1/R/R-40~1.5/etc/x64/Makeconf:229: file4a4c3d1a74e6.o] Error 127
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

I think I have RTools configured correctly and I am on a Windows 10 machine.

Thanks,
J.

Solved by finding the location of g++.exe and typing the following in R:

   Sys.setenv(BINPREF = "C:/rtools40/mingw64/bin/")
3 Likes

I got same problem, and cannot figure out using your method.
It shows the following errors:
Error in compileCode(f, code, language = language, verbose = verbose) :
C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: C:/Users/wcao/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): multiple definition of boost::math::detail::bessel_j0<long double>(long double)::P1'; file2f044aa74e25.o:file2f044aa74e25.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): first defined hereC:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/wcao/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QC[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QC]+0x0): multiple definition of boost::math::detail::bessel_j0(long double)::QC’; file2f044aa74e25.o:file2f044aa74e2
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

Hopefully one of our Windows experts will reply (@andrjohns any ideas?), but you could also try out our other R interface to Stan and see if that works with your current setup:

That’s not the same error message: you’re not getting an error 127.

I got same. when i use Sys.setenv(BINPREF = “C:/rtools40/mingw64/bin/”) and then get the error

Can you try restarting R (making sure that rstan doesn’t get loaded) and then run:

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

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

1 Like

I got the following error when I try to remove it:

remove.packages(c(“StanHeaders”,“rstan”))
Removing packages from ‘C:/Users/wtnic/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
Error in .rs.recursiveWalk(parsed, function(node) { :
reached elapsed time limit
Error in .rs.recursiveWalk(_node[[i]], fn, …) :
reached elapsed time limit
Error in as.POSIXct(time2) : reached elapsed time limit
Error in .rs.recursiveWalk(parsed, function(node) { :
reached elapsed time limit

That looks like you might have an issue with your R installation in general, not RStan.

Are you able to remove/install other packages? What output do you get from:

install.packages("jsonlite",type="source")
remove.packages("jsonlite")

The downloaded source packages are in
‘C:\Users\wtnic\AppData\Local\Temp\Rtmp6hu71x\downloaded_packages’

remove.packages(“jsonlite”)
Removing package from ‘C:/Users/wtnic/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)

And if you try to remove the packages again:

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

It shows there is no package rstan

And then try the install from source:

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

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

Warning in install.packages :
installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in
‘C:\Users\wcao\AppData\Local\Temp\RtmpmEYxFj\downloaded_packages’

ERROR: compilation failed for package ‘StanHeaders’

  • removing ‘C:/Users/wcao/Documents/R/win-library/4.0/StanHeaders’
    Warning in install.packages :
    installation of package ‘StanHeaders’ had non-zero exit status
    ERROR: dependency ‘StanHeaders’ is not available for package ‘rstan’
  • removing ‘C:/Users/wcao/Documents/R/win-library/4.0/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

sh: line 1: C:/rtools40/usr/mingw_32/bin/gcc: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.5/etc/i386/Makeconf:222: cvodes/cvodes_nls_stg1.o] Error 127
make: *** Waiting for unfinished jobs…
sh: line 1: C:/rtools40/usr/mingw_32/bin/gcc: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.5/etc/i386/Makeconf:222: cvodes/cvodes_nls_sim.o] Error 127
sh: line 1: C:/rtools40/usr/mingw_32/bin/gcc: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.5/etc/i386/Makeconf:222: cvodes/cvodes_ls.o] Error 127
sh: line 1: C:/rtools40/usr/mingw_32/bin/gcc: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.5/etc/i386/Makeconf:222: cvodes/cvodea_io.o] Error 127
sh: line 1: C:/rtools40/usr/mingw_32/bin/gcc: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.5/etc/i386/Makeconf:222: cvodes/cvodes_spils.o] Error 127
ERROR: compilation failed for package ‘StanHeaders’

  • removing ‘C:/Users/wcao/Documents/R/win-library/4.0/StanHeaders’

What do you get from:

Sys.getenv("BINPREF")
readLines("~/.Rprofile")

Sys.getenv(“BINPREF”)
[1] “C:/rtools40/usr/mingw_(WIN)/bin/" readLines("~/.Rprofile") [1] "Sys.setenv(BINPREF = \"C:/rtools40/usr/mingw_(WIN)/bin/”)"

You need to complete the RStan getting started instructions which cover this: Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub

Thank you very much. It does work now.