Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created!

Hi, I’m still getting a similar error after I finally got the previous one fixed (New error: cleanup_makevar(old) : argument "RMU" is missing, with no default - #42 by jonah)
So now, I get this:
Error in compileCode(f, code, language = language, verbose = verbose) :
sh: g++: command not foundmake: *** [C:/PROGRA~1/R/R-40~1.3/etc/x64/Makeconf:229: file1220515e66f3.o] Error 127
Error in sink(type = “output”) : invalid connection

I’m working on Windows with Rstudio version 4 and I just updated all my packages to make sure I had the latest version of everything. I’m strying to run a brm model with the brms package.

Any tips? Would be really highly appreciated!

Hi Karen,

Can you post the output from:

Sys.getenv("BINPREF")
Sys.getenv("PATH")
readLines("~/.R/Makevars.win")
readLines("~/.Renviron")
readLines("~/.Rprofile")

Hi Karen,

The Error in sink(type = "output") : invalid connection error went away and things started working again after a complete reinstall of my RStudio to the 1.4.1106 version, R to 4.0.4, reinstallation of all the packages, and installing rstan from source like remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan"). Now, I have new warnings 'config' variable 'CPP' is deprecated and clang -mmacosx-version-min=10.13 -E. But according to this thread, it seems like this isn’t something to worry about too much.

1 Like

Hi,
many thanks,
sorry for the late reply.
Looks like he is unable to locate some files!
I’ll also be re installing R to version 4.0.4 as suggested by arpasan, I’m apparently still on 4.0.3

Sys.getenv(“BINPREF”)
[1] “”
Sys.getenv(“PATH”)
[1] “C:\Program Files\Rtools\usr\bin;C:\Program Files\Rtools\usr\bin;C:\Program Files\R\R-4.0.3\bin\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath_target_19479906;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Matlab\R2020b\runtime\win64;C:\Program Files\Matlab\R2020b\bin;C:\Program Files\Git\cmd;D:\Users\kardpauw\AppData\Local\Microsoft\WindowsApps”
readLines(“~/.R/Makevars.win”)
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘D:/Users/kardpauw/Documents/.R/Makevars.win’: No such file or directory
readLines(“~/.Renviron”)
[1] “PATH="{RTOOLS40_HOME}\\usr\\bin;{PATH}"” “PATH="{RTOOLS40_HOME}\\usr\\bin;{PATH}"”
readLines(“~/.Rprofile”)
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘D:/Users/kardpauw/Documents/.Rprofile’: No such file or directory

Your RTools installation looks a little odd. Have you got rtools4 installed?

What output do you get from:

Sys.which("make")

Thanks Arpasan!
I checked my versions and turned out I am behind on both R and RStudio, so re-installing might really help, trying that now!

1 Like

Sys.which(“make”)
make
“C:\PROGRA~1\Rtools\usr\bin\make.exe”

I think the issue is that you’ve installed RTools in a non-standard directory, so R is looking in the wrong place. We just need to tell R where to look.

Can you run:

rt_path = gsub("\\","/",pkgbuild::rtools_path(),fixed=T)
rt_bin = paste0(substr(rt_path,1,nchar(rt_path)-8),"/mingw$(WIN)/bin/")
writeLines(paste0('Sys.setenv(BINPREF = "',rt_bin,'")'), con = "~/.Rprofile")

Then restart R and try the model again?

I’m not sure about the Rtools4, do you mean Rtools40?
I don’t think my Rtools is Rtools40, as it should show in the sys.which(“make”) I think.
Does it come automatically with newest versions of R or Rstudio, or do I install it separately?

Many thanks, guys!

It’s something that you have to install separately. If you’re not sure, can you try following the RStan Installation instructions: RStan Getting Started · stan-dev/rstan Wiki · GitHub to get configured

Exactly the same response, I’m afraid.
First a bunch of code, then:

Error in compileCode(f, code, language = language, verbose = verbose) :
sh: g++: command not foundmake: *** [C:/PROGRA~1/R/R-40~1.3/etc/x64/Makeconf:229: file1e604094389.o] Error 127
Error in sink(type = “output”) : invalid connection

In that case try running through the RStan installation instructions. Also make sure that you uninstall any other versions of RTools on your system, just to be sure

Thanks! I’ll let you know what happens

I installed the new rtools and reinstalled the new versions of R and Rstudio, plus then got stan and stanheaders again from github. And now my models are running again!

Thank you so much!!
Sorry for not just following the right instructions!

Hi, I’m new to Stan. I’ve searched and attempted several times to resolve the same issue as the headline of this post, but I’m still having the below error. Any help is greatly appreciated.

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

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : **
** sh: line 1: g++: command not foundmake: *** [C:/PROGRA~1/R/R-4.0.2/etc/x64/Makeconf:229:
file12a440014c6d.o] Error 127
In addition: Warning messages:
1: package ‘rstan’ was built under R version 4.0.5
2: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

What do you get from:

Sys.getenv("PATH")
readLines("~/.Renviron")
readLines("~/.Rprofile")
file.exists("C:/rtools40/mingw64/bin/g++.exe")

Thank you so much for your reply. I get the following:

Sys.getenv(“PATH”)
[1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.2\bin\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath_target_1185922296;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\MiKTeX\miktex\bin\x64;C:\Program Files\MATLAB\R2020a\bin;C:\Users\elnaz\AppData\Local\Microsoft\WindowsApps;C:\Users\elnaz\AppData\Roaming\TinyTeX\bin\win32”
readLines(“~/.Renviron”)
[1] “PATH="{RTOOLS40_HOME}\\usr\\bin;{PATH}"”
readLines(“~/.Rprofile”)
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/elnaz/Documents/.Rprofile’: No such file or directory
file.exists(“C:/rtools40/mingw64/bin/g++.exe”)
[1] TRUE

Can you install other packages from source?:

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

I ran and got the following:

install.packages(“jsonlite”, type = “source”)
Installing package into ‘C:/Users/elnaz/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL ‘https://cran.rstudio.com/src/contrib/jsonlite_1.7.2.tar.gz
Content type ‘application/x-gzip’ length 421716 bytes (411 KB)
downloaded 411 KB

  • installing source package ‘jsonlite’ …
    ** package ‘jsonlite’ successfully unpacked and MD5 sums checked
    ERROR: cannot remove earlier installation, is it in use?
  • removing ‘C:/Users/elnaz/Documents/R/win-library/4.0/jsonlite’
  • restoring previous ‘C:/Users/elnaz/Documents/R/win-library/4.0/jsonlite’
    Warning in file.copy(lp, dirname(pkgdir), recursive = TRUE, copy.date = TRUE) :
    problem copying C:\Users\elnaz\Documents\R\win-library\4.0\00LOCK-jsonlite\jsonlite\libs\x64\jsonlite.dll to C:\Users\elnaz\Documents\R\win-library\4.0\jsonlite\libs\x64\jsonlite.dll: Permission denied
    Warning in install.packages :
    installation of package ‘jsonlite’ had non-zero exit status

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

Can you restart R/RStudio and try again? Is the result any different?