Failing to install rstan 2.18 on Win10 x64

#17

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

C:\Rtools\bin;
C:\Rtools\mingw_64\bin;

I set the binpref, so that:

Sys.getenv("BINPREF") 
[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 https://win-builder.r-project.org/8Q3LUki5kcHs/rstan_2.18.1.zip 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.

0 Likes

#18

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

1 Like

#19

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

system("g++ -v")

?

0 Likes

#20

I now get

Sys.getenv("BINPREF") 
[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.

0 Likes

#21

Looking into it now. I probably messed up my Rtools installation it seems.

system("g++ -v")
Using built-in specs.
COLLECT_GCC=c:\Rtools\mingw_32\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/Rtools/mingw_32/bin/../libexec/gcc/i686-w64-mingw32/4.9.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.9.3/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-static --disable-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-posix-dwarf, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 4.9.3 (i686-posix-dwarf, Built by MinGW-W64 project)
0 Likes

#22

Okay, it is definitely picking up the 32bit version, whereas you need the 64bit option. My guess is that something along the lines of Paul’s solution to fix up the PATH will work for you.

1 Like

Error in compileCode
#23

You need to have

C:\Rtools\bin;
C:\Rtools\mingw_64\bin;

in your path and remove any other reference to Rtools, in particular

C:\Rtools\mingw_32\bin;
0 Likes

#24

@paul.buerkner Are you working with the latest frozen or unfrozen version of RTools?

0 Likes

#25

Latest unfrozen (Rtools 3.5).

0 Likes

#26

Okay, I think there are some differences between frozen and unfrozen. Keep yours the way it is, but the wiki has always been recommending frozen.

0 Likes

#27

I know and I tried that first. Had the exact same problem with Rtools 3.4.

0 Likes

#28

Thank you so much, @bgoodri and @paul.buerkner! It works now. Basically it was the solution Paul suggested here:

The “removing all other references to Rtools” was key. And I had to remove -m$(WIN), as Paul also pointed out above.

Thanks!

1 Like

#29

I was having these problems and following

  • @bgoodri’s instructions about setting BINPREF
  • and then @paul.buerkner’s suggestion to manually set the path to include c:\RTools\mingw_64\bin and install with INSTALL_opts="--no-multiarch"

worked so I could get rstan installed successfully.

0 Likes

#30

I’m getting errors on Windows 7 (Rtools35) after following the suggestions above. Where do I put the Makevars file on Windows?

> system("g++ -v")
Using built-in specs.
COLLECT_GCC=C:\Rtools\mingw_64\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=C:/Rtools/mingw_64/bin/../libexec/gcc/x86_64-w64-mingw32/4.9
.3/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.9.3/configure --host=x86_64-w64-mingw32 --bu
ild=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysr
oot=/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64 --with-gxx
-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-static --disable-s
hared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx
-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lt
o --enable-graphite --enable-checking=release --enable-fully-dynamic-string --en
able-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-v
ersion-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstra
p --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disa
ble-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --w
ith-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequi
sites/x86_64-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequ
isites/x86_64-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequ
isites/x86_64-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequ
isites/x86_64-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prere
quisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion=
'x86_64-posix-seh, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.
net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-4
93-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequi
sites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x8
6_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.
9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.
9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prer
equisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Je
roen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/lib -L/home/Jeroen
/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/lib -L/home/Jeroen/mingw-gcc-4
.9.3/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 4.9.3 (x86_64-posix-seh, Built by MinGW-W64 project)
> Sys.getenv("BINPREF")
[1] "C:/Rtools/mingw_$(WIN)/bin/"
> install.packages("rstan", type = "source", INSTALL_opts = "--no-multiarch")
Installing package into 'C:/Users/abreucbr/Documents/R/win-library/3.5'
(as 'lib' is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cran.cnr.berkeley.edu/src/contrib/rstan_2.18.1.tar.gz'
Content type 'application/x-gzip' length 833755 bytes (814 KB)
downloaded 814 KB

In R CMD INSTALL
* installing *source* package 'rstan' ...
** package 'rstan' successfully unpacked and MD5 sums checked
** libs
Error in .shlib_internal(args) :
  C++14 standard requested but CXX14 is not defined
* removing 'C:/Users/abreucbr/Documents/R/win-library/3.5/rstan'
* restoring previous 'C:/Users/abreucbr/Documents/R/win-library/3.5/rstan'

The downloaded source packages are in
        'C:\Users\abreucbr\AppData\Local\Temp\RtmpQfGE66\downloaded_packages'
Warning message:
In install.packages("rstan", type = "source", INSTALL_opts = "--no-multiarch") :

  installation of package 'rstan' had non-zero exit status
>
0 Likes

#31

Probably something like C:\Users\*YOUR_USER_NAME*\Documents\.R.

0 Likes

#32

I was also having these problems (on a Windows 7 machine) and the recipe by Ben and Paul worked well for installing the 64 bit rstan from source (apart from having to install some dependencies separately afterwards (RCurl, igraph, rsconnect, threejs, shinystan)).

For people interested in getting the 32 bit version installed as well I can tell that I finally managed to get that in too. The reason I wanted it was that it was needed for installing other packages that use multiarch installations (e.g. rethinking by McElreath)

What I did was to temporarily change PATH c:\RTools\mingw_64\bin to c:\RTools\mingw_32\bin and then in 32 bit R use bgoodri’s .zip binary (see above)
install.packages(“C:/Users/Martin Stjernman/Downloads/rstan_2.18.1.zip”, INSTALL_opts = “–no-multiarch”)
(Then set PATH back to c:\RTools\mingw_64\bin)

For reasons I can’t remember I could not use the source version of rstan nor could I set dependencies=TRUE in the above. This meant that when later installing f ex in rethinking in my 64 bit R I had to manually (i.e. package by package) install many dependencies in my 32 bit R which was needed by rethinking (The installer constantly told me what was missing and then it was just to install it into my 32 bit R). Finally, I got rethinking installed as well and it seems to work (on 64 bit R anyway).

Hope this was of some help to somebody.

Sincerely,
Martin

0 Likes

#33

Thanks! That worked. Installation was completed successfully! :)

0 Likes

#34

@paul.buerkner I got multiarch working. Try with the newest Windows instructions.

1 Like

#35

Hi Ben, I can confirm that it works with multiarch now! Thank you so much!

Just two minor comments / questions:

  1. There is a comma missing in the R chunk directly after Configuration.
  2. What happens if the Makevars file already contains CXX14 compiler flags
    and we keep adding lines with CXX14 flags. Does the last line overwrite the configurations in the former?
0 Likes

#36

Yes

0 Likes