Failing to install rstan 2.18 on Win10 x64

I am trying to install rstan 2.18.1 from source on Windows 10. My C++14 compiler flags are correctly set, stanHeaders 2.18 installs fine from source and also rstan x32 compilation and installation works smoothly.

Similarly the x64 version starts compiling quite a few files successfully, but then fails with

g++ -std=c++1y -shared -s -static-libgcc -o rstan.dll tmp.def chains.o init.o lang__ast_def.o lang__grammars__bare_type_grammar_inst.o lang__grammars__expression07_grammar_inst.o lang__grammars__expression_grammar_inst.o lang__grammars__functions_grammar_inst.o lang__grammars__indexes_grammar_inst.o lang__grammars__program_grammar_inst.o lang__grammars__semantic_actions.o lang__grammars__statement_2_grammar_inst.o lang__grammars__statement_grammar_inst.o lang__grammars__term_grammar_inst.o lang__grammars__var_deccls_grammar_inst.o lang__grammars__whitespace_grammar_inst.o misc.o pointer-tools.o sparse_extractors.o stanc.o -LC:/PROGRA~1/R/R-35~1.1/bin/x64 -lR
C:/PROGRA~1/R/R-35~1.1/bin/x64/R.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

which is strange, because the R.dll is clearly in its place.

@bgoodri I hope I didn’t overlook a topic discussing this issue, but I would expect that if I have it, many other windows users might have it as well.


I had that issue over the weekend as well Paul. Part of it was that I had messed up my PATH setting, but then other weird stuff happened too. In the end, I rolled back to StanHeaders 2.17.2 and nuked and reinstalled my Rtools install (3.4 not 3.5 as it isn’t frozen yet) and that seemed to do the trick.

No idea if that would work for others though.

Happy to help out if you need any profile information from my machine.

this happened to my collaborator last week. she works at a hospital, work machines are managed by remote IT folks. her R install was upgraded. RStudio then upgraded all installed packages, at which point RStan could no longer install programs.
she had to ask her IT folks to reinstall RTools for her, but as of yesterday, there were definitely PATH problems - the RTools version was correct, but it could no longer find the path to the g++ compiler.

as I don’t have access to a windows machine myself, I’m unable to figure out what might have happened.

rolling back to StanHeaders 2.17.[2,3] is the consensus solution in other versions of this thread so far, but we need to figure out what’s going on, so yes, any info you can send along would be great!

I was about to post a lot of errors from different windows machines / different makevars attempts, but I just got one working, using this line:
CXX14 = g++ -std=c++1y
in my makevars. At first this gave me errors but then I deleted and reinstalled rtools, including
in my path, and it seems to be working…

edit: this was for a windows 7 w64 box, r.3.5.0 and rtools 3.5


I did what you did, Charles, but got:

C:\Users\win7\AppData\Local\Temp\ccDMV70q.s: Assembler messages: C:\Users\win7\AppData\Local\Temp\ccDMV70q.s: Fatal error: can't close lang__grammars__statement_grammar_inst.o: File too big make: *** [C:/PROGRA~1/R/R-35~1.1/etc/i386/Makeconf:215: lang__grammars__statement_grammar_inst.o] Error 1 ERROR: compilation failed for package 'rstan'

I’m on Windows 7, though. (I know this is a thread for Windows 10, but I didn’t want to start a new thread.) Anyone got any ideas?

As @bgoodri correctly pointed out below, I missed something in Makevars. Anyone with the same problem, check out this. I also had to reinstall Rtools and (manually) add C:\Rtools\mingw_64\bin, just as @Charles_Driver pointed out. But now I get the error message that Paul mentions in the first post. I’ll try the binary install…

@Max_Mantei I am pretty sure that error is from not having -O2 or -O3 in CXX14FLAGS.

1 Like

@paul.buerkner We’ll have to get this figured out, but in the meantime you can binary install from

Thanks @bgoodri! I am now experimenting with different rtools versions and system path info and report back as soon as I found a working version.

@paul.buerkner @Max_Mantei Do you need a CXX14 = g++ -m$(WIN) -std=c++1y in ~/.R/Makevars to build a multiarch binary?

That could be the solution. Let me try that. In the meantime, I solved the problem with the following approach on Win10, R 3.5.1 64-bit, and Rtools 3.5.

  1. I included the following two lines in the System PATH (and removed all other references to Rtools):
  1. I installed the package without multiarch.
install.packages("rstan", type = "source", INSTALL_opts = "--no-multiarch")
1 Like

@paul.buerkner What does Sys.getenv("BINPREF") output?

[1] ""

under all settings I tried so far.

That is probably the root of the problem

(Honestly, I don’t even know what that means.)

I tried this and it gave me something new (still an error, though):

*** arch - x64 g++ -m64 -std=c++1y -I"C:/PROGRA~1/R/R-35~1.1/include" -DNDEBUG -I"../inst/include" -I"`"C:/PROGRA~1/R/R-35~1.1/bin/x64/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/Users/win7/Documents/R/win-library/3.5/Rcpp/include" -I"C:/Users/win7/Documents/R/win-library/3.5/RcppEigen/include" -I"C:/Users/win7/Documents/R/win-library/3.5/BH/include" -I"C:/Users/win7/Documents/R/win-library/3.5/StanHeaders/include" -O3 -Wno-unused-variable -Wno-unused-function -c chains.cpp -o chains.o chains.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in // This file is part of RStan ^ make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: chains.o] Error 1 ERROR: compilation failed for package 'rstan'

Dunno if it’s important for my case but

[1] ""

is what I get.

Setting the BINPREF environmental variable is important for all cases. See

ran across this yesterday and tried setting BINPREF environmental variable - no luck.

So, to recap: I installed the latest Rtools with:


I set the binpref, so that:

[1] "C:/Rtools/mingw_$(WIN)/bin/"

My Makevars looks like this:

CXX14 = g++ -m$(WIN) -std=c++1y
CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function

Running install.packages("rstan") still fails:

*** arch - x64
g++ -m64 -std=c++1y  -I"C:/PROGRA~1/R/R-35~1.1/include" -DNDEBUG -I"../inst/include" -I"`"C:/PROGRA~1/R/R-35~1.1/bin/x64/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/Users/win7/Documents/R/win-library/3.5/Rcpp/include" -I"C:/Users/win7/Documents/R/win-library/3.5/RcppEigen/include" -I"C:/Users/win7/Documents/R/win-library/3.5/BH/include" -I"C:/Users/win7/Documents/R/win-library/3.5/StanHeaders/include"        -O3 -Wno-unused-variable -Wno-unused-function -c chains.cpp -o chains.o
chains.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
 // This file is part of RStan
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: chains.o] Error 1
ERROR: compilation failed for package 'rstan'

This also fails (similarly as above):

install.packages("rstan", type = "source", INSTALL_opts = "--no-multiarch")

Installing from works, but when I want to compile a Stan model it throws another error at me:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! filea6040b6550a.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: filea6040b6550a.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-35~1.1/bin/x64/R CMD SHLIB filea6040b6550a.cpp 2> filea6040b6550a.cpp.err.txt' had status 1

I feel really stupid.

What happens if you remove -m$(WIN) from Makevars?

1 Like

On Google, there are many hits for that quote. Also, what is the output of

system("g++ -v")


I now get

[1] "C:/Rtools/mingw_$(WIN)/bin/"

but I can’t install rstan in multiarch mode. I think this is fine given that I don’t need the 32-bit version and just building the 64-bit version works as I wrote above. So consider this solved from may part.