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

Hi,
I am new to rstan. The installation was successfully done within Windows10, in C:
However, when I try to run the first model after the installation instructions, I get the following error message:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file27b46fc111f7.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
#include <stan/model/model_header.hpp>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: file27b46fc111f7.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ā€˜C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file27b46fc111f7.cpp 2> file27b46fc111f7.cpp.err.txtā€™ had status 1
Error in sink(type = ā€œoutputā€) : invalid connection

I had a look at the other similar posts, (re-installation, installing in C:) but they have not worked for me. Any advise would be most appreciated.

Thank you.

It probably installed StanHeaders to some directory that it cannot find. What is

system.file("include", "src", "stan", "model", "model_header.hpp",
            package = "StanHeaders")

?

Thank you for your response.

system.file(ā€œincludeā€, ā€œsrcā€, ā€œstanā€, ā€œmodelā€, ā€œmodel_header.hppā€, package = ā€œStanHeadersā€)
[1] ā€œ\\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model_header.hppā€

Yeah, having it in a networked drive is tricky. When you do

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

what is the compilation argument, i.e. the line in the middle of the output that starts with g++?

The output is:
Compilation argument:
C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file27b442af3432.cpp 2> file27b442af3432.cpp.err.txt
C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/Rcpp/include/" -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/RcppEigen/include/" -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/BH/include" -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/StanHeaders/include/" -I"\Jericho/home/petros.boutselis/Documents/R/win-library/3.6/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -std=c++1y -march=core2 -O2 -Wall -mtune=generic -c file27b442af3432.cpp -o file27b442af3432.o
file27b442af3432.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
#include <stan/model/model_header.hpp>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: file27b442af3432.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

Hi,
Sorry for coming back, but I wanted to make sure that I have provide you with the right output?
Thank you again for your time.

That is the right output, but I think it does not know what to do with paths that start with \Jericho. Does

example(cxxfunction, package = "inline", run.dontrun = TRUE)
work?

Unfortunately not:

example(cxxfunction, package = ā€œinlineā€, run.dontrun = TRUE)

cxxfnc> # default plugin
cxxfnc> fx ā† cxxfunction( signature(x = ā€œintegerā€, y = ā€œnumericā€ ) , ā€™
cxxfnc+ return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
cxxfnc+ ā€™ )

cxxfnc> fx( 2L, 5 )
[1] 10

cxxfnc> # Rcpp plugin
cxxfnc> if( require( Rcpp ) ){
cxxfnc+
cxxfnc+ fx ā† cxxfunction( signature(x = ā€œintegerā€, y = ā€œnumericā€ ) , ā€™
cxxfnc+ return wrap( as(x) * as(y) ) ;
cxxfnc+ ', plugin = ā€œRcppā€ )
cxxfnc+ fx( 2L, 5 )
cxxfnc+
cxxfnc+ ## equivalent shorter form using rcpp()
cxxfnc+ fx ā† rcpp(signature(x = ā€œintegerā€, y = ā€œnumericā€),
cxxfnc+ ā€™ return wrap( as(x) * as(y) ) ; ')
cxxfnc+
cxxfnc+ }
Loading required package: Rcpp

Attaching package: ā€˜Rcppā€™

The following object is masked from ā€˜package:inlineā€™:

registerPlugin

file26cc77defd9.cpp:4:18: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: file26cc77defd9.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
1:
2: // includes from the plugin
3:
4: #include <Rcpp.h>
5:
6:
7: #ifndef BEGIN_RCPP
8: #define BEGIN_RCPP
9: #endif
10:
11: #ifndef END_RCPP
12: #define END_RCPP
13: #endif
14:
15: using namespace Rcpp;
16:
17: // user includes
18:
19:
20: // declarations
21: extern ā€œCā€ {
22: SEXP file26cc77defd9( SEXP x, SEXP y) ;
23: }
24:
25: // definition
26:
27: SEXP file26cc77defd9( SEXP x, SEXP y ){
28: BEGIN_RCPP
29:
30: return wrap( as(x) * as(y) ) ;
31:
32: END_RCPP
33: }
34:
35:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file26cc77defd9.cpp:4:18: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: file26cc77defd9.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ā€˜C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file26cc77defd9.cpp 2> file26cc77defd9.cpp.err.txtā€™ had status 1

Both of these error messages are saying it cannot find files that are in packages that are installed in your home directory. I think you need to figure out a way to install packages somewhere in C:/. Or maybe map the network drive your home directory is on to some place in C:/ or at least that has the same conventions for specifying paths.

Thank you very much for the advice.

Hi! Sorry to hijack this thread, but Iā€™m running into a similar problem. If you prefer I open a new thread, please let me know.

When trying to compile a Stan model I get the following error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
Compilation ERROR, function(s)/method(s) not created! file339c2b2f763d.cpp:31:40: error: 
expected template-name before '<' token
   : public stan::model::model_base_crtp<model339c3e6c6dd_8b930d0c26abd40c299b4f2a09342bab> {
                                        ^
file339c2b2f763d.cpp:31:40: error: expected '{' before '<' token
file339c2b2f763d.cpp:31:40: error: expected unqualified-id before '<' token
In file included from J:/Documents/R/win-library/3.6/BH/include/boost/winapi/time.hpp:13:0,
                 from J:/Documents/R/win 
library/3.6/BH/include/boost/date_time/microsec_time_clock.hpp:24,
                 from J:/Documents/R/win- 
library/3.6/BH/include/boost/date_time/posix_time/posix_time_types.hpp:11,
                 from J:/Documents/R/win-library/3.6/rstan/include/rstan/stan_fit.hpp:13,
                 from J:/Documents/R/win-library/3.6/rstan/include/rstan/rstaninc.hpp:3,
                 from file339c2b2f763d.cpp:520:
J:/Documents/R/win-library/3.6/BH/include
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file339c2b2f763d.cpp 2> 
file339c2b2f763d.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Iā€™m not quite sure whatā€™s going wrong, although it seems similar to the problem described here. Iā€™m able to run

 example(cxxfunction, package = "inline", run.dontrun = TRUE)

without errors.

Do you have any advice on what I could try to get Stan working?

I think the easiest thing to do would be to install the rstan that goes with that version of StanHeaders. But things with CRAN are a bit in flux at the moment, so you have to do

install.packages("https://win-builder.r-project.org/l26BR4T0nUlo/rstan_2.21.1.zip",
                 repos = NULL)
1 Like

Thanks! I tried but unfortunately run into a new problem:

Error: package or namespace load failed for ā€˜rstanā€™ in inDL(x, as.logical(local), as.logical(now), ...):
unable to load shared object 'J:/Documents/R/win-library/3.6/rstan/libs/x64/rstan.dll':
LoadLibrary failure:  The specified procedure could not be found.
In addition: Warning message:
package ā€˜rstanā€™ was built under R version 4.0.0

Hmm. Maybe try installing from GitHub

remotes::install_github("stan-dev/rstan", ref = "develop",
                        subdir = "rstan/rstan")

?

Sadly Iā€™m having some trouble getting that to compile from source. Variations of the errors and warnings I see all the time are:

J:/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/require_generics.hpp:736:53: warning: variadic 
templates only available with -std=c++11 or -std=gnu++11
template <template <class...> class TypeCheck, class... Check>
                                                    ^
J:/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/require_generics.hpp:737:1: error: expected 
unqualified-id before 'using'
using require_all_not_std_vector_st
^

And it ends with

make: *** [C:/PROGRA~1/R/R-36~1.2/etc/i386/Makeconf:215: sparse_extractors.o] Error 1
ERROR: compilation failed for package 'rstan'
* removing 'J:/Documents/R/win-library/3.6/rstan'
* restoring previous 'J:/Documents/R/win-library/3.6/rstan'
Error: Failed to install 'rstan' from GitHub:
(converted from warning) installation of package 
ā€˜C:/Users/maum/AppData/Local/Temp/RtmpIXM05M/file3e88678f6169/rstan_2.21.1.tar.gzā€™ had non-zero exit status
In addition: Warning message:
In utils::untar(tarfile, ...) :
ā€˜tar.exe -xf "C:\Users\maum\AppData\Local\Temp\RtmpIXM05M\file3e886f114dd6.tar.gz" -C 
"C:/Users/maum/AppData/Local/Temp/RtmpIXM05M/remotes3e88eac4bec"ā€™ returned error code 1

Unfortunately I have no idea what these errors mean - any advice is greatly appreciated.

P.S. the installation errors and warnings go on for multiple screens - let me know if you want me to capture them entirely.

Hold on, for whatever reason, using rstan 2.19.2 with StanHeaders 2.21.0-1 is now working (mostly) as expected. Iā€™ll do some more testing, but if you donā€™t hear from me, please donā€™t spend any time on this anymore! :-)

I have spent the last 3 months on it, so another little bit wonā€™t hurt much.

1 Like

Haha, thanks for your help so far!

Unfortunately I seem to have celebrated a bit too early. Some of the simpler Stan models (i.e. 8 schools) compile and sample just fine, but a slightly more complex model gives this error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! 
C:\Users\maum\AppData\Local\Temp\cc553bQO.s: Assembler messages:
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:8510: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:8512: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:17711: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:88036: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:88038: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:88040: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:121760: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:186054: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.s:188560: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\cc553bQO.
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file2828102563db.cpp 2>     file2828102563db.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Does this seem related?

To be precise this shows up when trying to compile the model with stan_model().

Things like that are usually due to having -mtune=native -march=native and the compiler misdiagnosing the processor. If you have that in CXX11FLAGS or something, try removing it.

1 Like

Hi. Not sure whether it is acceptable to use this thread but I am experiencing issues compiling Stan models. I installed RStan without any issues.
Win 10, 64 bit, R 3.6.2, Rtools 3.5.0.4
However, when I try to run the following command:
example(stan_model, run.dontrun = TRUE)
I get the following errors:

g++.exe: error: Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
g++.exe: error: Files/R/R-3.6.2/library/StanHeaders/include: No such file or directory
g++.exe: error: Files/R/R-3.6.2/library/RcppEigen/include: No such file or directory

The ā€œcompilation argumentā€ is as follows:

C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file355079371150.cpp 2> file355079371150.cpp.err.txt
C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"C:/Program Files/R/R-3.6.2/library/Rcpp/include/" -I"C:/Program Files/R/R-3.6.2/library/RcppEigen/include/" -I"C:/Program Files/R/R-3.6.2/library/RcppEigen/include/unsupported" -I"C:/Program Files/R/R-3.6.2/library/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src/" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/" -I"C:/Program Files/R/R-3.6.2/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -std=c++1y -march=core2 -include C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I C:/Program Files/R/R-3.6.2/library/StanHeaders/include -I C:/Program Files/R/R-3.6.2/library/RcppEigen/include -O3 -march=corei7 -mtune=corei7 -c file355079371150.cpp -o file355079371150.o

I noticed that the files or directories that cannot be found happen to be those that are not in quotes in the compilation argument, namely

-include C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I C:/Program Files/R/R-3.6.2/library/StanHeaders/include -I C:/Program Files/R/R-3.6.2/library/RcppEigen/include

and the errors complain that
Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp
doesnā€™t exist, etc. The paths have been mangled.

Needless to say, these files and directories all exist on my machine.

Is there a way to force the paths to be properly quoted? And would that solve the problem?

Thank you for any help you may be to provide.