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

Sorry to hear that!

Are you able to update to R4.0 and RTools4? That usually fixes these kinds of problems as well.

Thank you! I didn’t know that this was the problem. I updated it and installed it again. It worked!

Fantastic! Sorry we took so long to get you working!

1 Like

Hi, I’m having the same issue. This is the error message

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Core:82:
In file included from /usr/local/clang7/include/c++/v1/new:91:
In file included from /usr/local/clang7/include/c++/v1/exception:82:
In file included from /usr/local/clang7/include/c++/v1/cstdlib:86:
/usr/local/clang7/include/c++/v1/stdlib.h:111:82: error: use of undeclared identifier 'labs'; did you mean 'abs'?
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                                                                 ^
/usr/local/clang7/include/c++/v1/s
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file2cab7b41d3.cpp 2> file2cab7b41d3.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

I tried updating Xcode, and doing

install.packages("https://cran.r-project.org/src/contrib/Archive/StanHeaders/StanHeaders_2.19.0.tar.gz",
                 repos = NULL)

but to no avail. Any hints as to how I could get Stan to work? Thanks!

Okay, I reinstalled my R, RStudio, all the packages, and now I have a new error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  /usr/local/clang7/include/c++/v1/cstdlib:119:9: error: no member named 'strtoul' in the global namespaceusing ::strtoul;      ~~^fatal error: too many errors emitted, stopping now [-ferror-limit=]20 errors generated.make: *** [file16e67ff15967.o] Error 1
In addition: Warning messages:
1: In system2(CXX, args = ARGS) : error in running command
2: In file.remove(c(unprocessed, processed)) :
  cannot remove file '/var/folders/qp/2x2fhtc96vb35rm4vwgcp64c0000gn/T//RtmpllMEia/file16e61be9a21e.stan', reason 'No such file or directory'
Error in sink(type = "output") : invalid connection

?

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® Management Engine Components\DAL;C:\Program Files\Intel\Intel® 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