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

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.

StanHeaders is apparently reverted on CRAN to 2.19.x but they still have 2.21.x binaries. So, I would start a clean R session and do

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

and then things should work again.

Thank you very much for your prompt response. I re-installed StanHeaders using the command you provided and the version is now 2.19.0. I no longer get the previous errors about missing files, which is great. However, compilation still fails, this time with the following error message. My installed version of RStan is at 2.19.2.

Again, any help will be much appreciated. Thanks.

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

Sadly that doesn’t seem to be the case. I get the same error. I now have StanHeaders at 2.19.0 and my makevars.win is as follows:

CXX14=$(BINPREF)g++
CXX14FLAGS=-O3
CXX11FLAGS=-O3

Is that as it should be?

You and @jhaeberl are also going to have to reinstall rstan, possibly from source.

Deleted Rstan and tried to install from source but unfortunately that failed with many errors. Here are the first few lines of output from the build process

* installing *source* package 'rstan' ...
** package 'rstan' successfully unpacked and MD5 sums checked
** using staged installation
** libs


"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c sparse_extractors.cpp -o sparse_extractors.o


"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c misc.cpp -o misc.o


"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c stanc.cpp -o stanc.o


"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c init.cpp -o init.o


"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c pointer-tools.cpp -o pointer-tools.o


"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c chains.cpp -o chains.o


In file included from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/include/phoenix_limits.hpp:11:0,
                 from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/home/support/meta_compiler.hpp:16,
                 from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/home/qi/meta_compiler.hpp:14,
                 from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/home/qi/action/action.hpp:14,
                 from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/home/qi/action.hpp:14,
                 from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/home/qi.hpp:14,
                 from C:/Program Files/R/R-3.6.2/library/BH/include/boost/spirit/include/qi.hpp:16,
                 from ./stan/lang/grammars/whitespace_grammar.hpp:4,
                 from ./stan/lang/grammars/program_grammar.hpp:6,
                 from C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src/stan/lang/parser.hpp:5,
                 from C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src/stan/lang/compiler.hpp:7,
                 from stanc.cpp:22:
C:/Program Files/R/R-3.6.2/library/BH/include/boost/phoenix/core/limits.hpp:44:0: warning: "BOOST_PHOENIX_NO_VARIADIC_EXPRESSION" redefined
 # define BOOST_PHOENIX_NO_VARIADIC_EXPRESSION
 ^
<command-line>:0:0: note: this is the location of the previous definition
"C:\Rtools\mingw_64\bin\g++.exe"  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"../inst/include" -I"." -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -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/BH/include" -I"C:/Program Files/R/R-3.6.2/library/StanHeaders/include"        -O3 -march=native -mtune=native -c stan/lang/ast_def.cpp -o stan/lang/ast_def.o


In file included from chains.cpp:19:0:
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp: In function 'typename boost::math::tools::promote_args<T>::type stan::math::mean(const std::vector<T>&)':
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:63: error: an array reference cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                               ^
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:63: error: '&' cannot appear in a constant-expression
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:68: error: '.' cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                                    ^
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:73: error: a function call cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                                         ^
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: a function call cannot appear in a constant-expression
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
                                                                          ^
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: template argument 3 is invalid
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: template argument 4 is invalid
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:74: error: template argument 6 is invalid
C:/Program Files/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:24:27: error: template argument 1 is invalid
   Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());

Then I installed Rstan from CRAN, version 2.19.2 but I got the same error as I reported above when trying to compile a model. What am I missing? Thanks.

So, those errors are from doing

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

after installing StanHeaders 2.19.x ?

Yes, that is correct.

That should be CXX14=$(BINPREF)g++ -std=c++1y. I think the lack of the -std=c++1y might also be the cause of the errors @jhaeberl is seeing.

1 Like

Perfect. I was able to install rstan from source and that did indeed resolve the model compilation issues. So all is well.

Many thanks for your help!

I was able to install rstan from source after installing StanHeaders 2.19.0 and updating my Makevars.win to

CXX14=$(BINPREF)g++ -std=c++1y
CXX14FLAGS=-O3
CXX11FLAGS=-O3

but I sadly still get an error when trying to compile a Stan model (that works on a different machine)

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created!
C:\Users\maum\AppData\Local\Temp\ccErw77r.s: Assembler messages:
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:7481: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:7483: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:17828: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:89165: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:89167: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:89169: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:94157: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:121179: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s:167542: Error: invalid register for .seh_savexmm
C:\Users\maum\AppData\Local\Temp\ccErw77r.s
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB filebc4c74170.cpp 2> filebc4c74170.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Is there anything else I could try?

Do you set -mtune=native -march=native at runtime? If so, don’t.

I don’t think that I’m doing that. I’ll have a look at my environment variables right before and after trying to compile this model and then report back.

The part that gets added when trying to compile the model is this:

Sys.getenv()
PKG_CPPFLAGS                                     -I"J:/Documents/R/win-library/3.6/Rcpp/include/"
                                                 -I"J:/Documents/R/win-library/3.6/RcppEigen/include/"
                                                 -I"J:/Documents/R/win-library/3.6/RcppEigen/include/unsupported"
                                                 -I"J:/Documents/R/win-library/3.6/BH/include"
                                                 -I"J:/Documents/R/win-library/3.6/StanHeaders/include/src/"
                                                 -I"J:/Documents/R/win-library/3.6/StanHeaders/include/"
                                                 -I"J:/Documents/R/win-library/3.6/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS
                                             -std=c++1y
PKG_LIBS                                         -L"J:/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders

From this I don’t get the impression that the -mtune=native -march=native gets added at any point. I also don’t see it anywhere else - is there any other place I may be missing?

Nevermind, it seems there was a setting somewhere in the script that did overwrite LOCAL_CPPFLAGS; removing that seems to have fixed the problem. Apologies for missing that!

Thanks for your help @bgoodri!

1 Like