Skip to content

Commit d024270

Browse files
authored
Merge pull request #630 from stan-dev/windows-toolchains
Update windows instructions for all rtools versions
2 parents 1003b48 + 37d7e87 commit d024270

1 file changed

Lines changed: 80 additions & 22 deletions

File tree

src/cmdstan-guide/installation.Rmd

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ We recommend installing CmdStan in a new conda environment:
3535
conda create -n stan -c conda-forge cmdstan
3636
```
3737

38-
This command creates a new conda environment named `stan` and
38+
This command creates a new conda environment named `stan` and
3939
downloads and installs the `cmdstan` package
4040
as well as CmdStan and the required C++ toolchain.
4141

@@ -283,14 +283,9 @@ then the call to `mingw32-make` will result in error message:
283283
```
284284
'mingw32-make' is not recognised as an internal or external command
285285
```
286-
To fix this, you should make sure that the RTools installation is
287-
in your `PATH` environment variable.
288-
In addition, if you have the RTools 4.0 toolchain, then call the utility `pacman`
289-
to register the right version of make:
290-
```
291-
pacman -Sy mingw-w64-x86_64-make
292-
```
293-
See: https://discourse.mc-stan.org/t/cmdstan-installation-on-windows/11287/6
286+
To fix this, ensure you have followed the steps for adding the toolchain to your
287+
`PATH` and installing the additional utilities covered in the
288+
[configuration instructions](#windows)
294289

295290

296291
**Windows: 'g++' or 'cut' is not recognized**
@@ -300,8 +295,9 @@ resulting in the error message:
300295
```
301296
'cut' is not recognized as an internal or external command, operable program or batch file.
302297
```
303-
The solution is to add `mingw_64/bin` directory to the user `PATH` environment variable. See:
304-
https://discourse.mc-stan.org/t/errors-when-using-cmdstan-model/14984/21
298+
To fix this, ensure you have followed the steps for adding the toolchain to your
299+
`PATH` and installing the additional utilities covered in the
300+
[configuration instructions](#windows)
305301

306302

307303
## C++ Toolchain {#cpp-toolchain}
@@ -384,20 +380,82 @@ g++ --version
384380
mingw32-make --version
385381
```
386382

387-
We recommend using the [RTools 4.0](https://cran.r-project.org/bin/windows/Rtools/rtools40.html) toolchain
388-
which contains a `g++ 8` compiler and `mingw32-make`, the native Windows equivalent of the GNU Make utility.
389-
RTools provides an
390-
[installer](https://github.com/r-windows/rtools-installer/releases/download/2022-02-06/rtools40-x86_64.exe)
391-
utility. After running the installer, you must add
392-
the location of the Rtools compiler and make utilities
393-
to the `PATH` environment variable. If you have `Rtools40`, these should be:
383+
CmdStan is known compatible with the RTools40, RTools42, and RTools43 toolchains. These require slightly
384+
different steps to configure, so please follow the appropriate steps below. All toolchains will require
385+
updating your `PATH` variable, See [these instructions](https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/)
386+
for details on changing the `PATH` if you are unfamiliar. The following instructions will assume that the default installation
387+
directory was used, so be sure to update the paths accordingly if you have chosen a different
388+
directory.
389+
390+
##### RTools40
391+
392+
RTools40 provides both a standard `g++-8` toolchain and a `g++-10` Universal C Runtime (UCRT) toolchain.
393+
Note the that newer `g++-10` UCRT toolchain is only available for 64-bit systems, whereas the `g++-8`
394+
toolchain is available for both. Additionally the UCRT is only natively supported on Windows 10 and newer,
395+
older systems will require a [Microsoft update](https://support.microsoft.com/en-us/topic/update-for-universal-c-runtime-in-windows-c0514201-7fe6-95a3-b0a5-287930f3560c)
396+
397+
###### Installation
398+
399+
Download the [installer](https://github.com/r-windows/rtools-installer/releases/download/2022-02-06/rtools40-x86_64.exe)
400+
and complete the prompts to install.
401+
402+
Next, you need to add the location of the toolchain to your `PATH` environment variable so that it
403+
can be called from the command line. Add the following lines to your `PATH`:
404+
```
405+
C:\rtools40\usr\bin
406+
407+
# Add only one of the below
408+
C:\rtools40\mingw32\bin # 32-bit g++-8
409+
C:\rtools40\mingw64\bin # 64-bit g++-8
410+
C:\rtools40\ucrt64\bin # 64-bit g++-10 (UCRT)
411+
```
412+
413+
CmdStan additionally needs the `mingw32-make` utility, which you can install using RTools.
414+
Navigate to the installation directory (e.g., `C:\rtools40`) and launch the `msys2.exe` file.
415+
Execute the appropriate command below to install `mingw32-make` for your selected toolchain:
394416
```
395-
C:\RTools\RTools40\usr\bin
396-
C:\RTools\RTools40\mingw64\bin
417+
pacman -Sy mingw-w64-i686-make # 32-bit g++-8
418+
pacman -Sy mingw-w64-x86_64-make # 64-bit g++-8
419+
pacman -Sy mingw-w64-ucrt-x86_64-make # 64-bit g++-10 (UCRT)
397420
```
398421

399-
See [these instructions](https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/)
400-
for details on changing the `PATH`.
422+
##### RTools42 & RTools43
423+
424+
Both RTools42 & RTools43 provide 64-bit UCRT toolchains, where RTools42 provides g++-10 and
425+
RTools43 provides g++-12. The installation/configuration is identical for both toolchains.
426+
427+
###### Installation
428+
429+
Download the installer for your preferred toolchain and complete the prompts for installation:
430+
431+
- [RTools42](https://cran.r-project.org/bin/windows/Rtools/rtools42/files/rtools42-5355-5357.exe)
432+
- [RTools43](https://cran.r-project.org/bin/windows/Rtools/rtools43/files/rtools43-5550-5548.exe)
433+
434+
Next, you need to add the toolchain directory to your `PATH` variable. Add the appropriate lines
435+
from below:
436+
```
437+
# RTools42
438+
C:\rtools42\usr\bin
439+
C:\rtools42\ucrt64\bin
440+
441+
# RTools43
442+
C:\rtools43\usr\bin
443+
C:\rtools43\ucrt64\bin
444+
```
445+
446+
Next, you need to install the `mingw32-make` utility and some additional compiler dependencies.
447+
Navigate to the installation directory of the toolchain and launch the `msys2.exe` file.
448+
Execute the below commands to install the needed dependencies:
449+
```
450+
pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc
451+
```
452+
453+
Finally, some additional compilation flags will be needed for CmdStan. Navigate to
454+
the CmdStan/make directory and create a file called `local`. Add the following lines to the file:
455+
```
456+
CXXFLAGS += -Wno-nonnull
457+
TBB_CXXFLAGS= -U__MSVCRT_VERSION__ -D__MSVCRT_VERSION__=0x0E00
458+
```
401459

402460
__32-bit Builds__
403461

0 commit comments

Comments
 (0)