Failing to install rstan 2.18 on Win10 x64

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)

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

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;

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

Latest unfrozen (Rtools 3.5).

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.

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

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

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.

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
>

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

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

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

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

1 Like

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?

Yes

@paul.buerkner Do you experience crashes when adding -march=native -mtune=native to CXX1*FLAGS on newer Windows hardware? I do not, but then again I have Windows 7. The native has caused people trouble over the years, but that may have been due to the lack of standards before C++11.

On my Windows 10 Laptop with the following Makevars

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

I don’t run into any problems.

Which Intel processor does that laptop have?

Intel® Core™ i7-8650U CPU @ 1.90GHz, 2112 MHz, 4 cores, 8 logical processors