Installation on Windows revisited

I had a bit of trouble with this the last time I tried, and whined about it on the list. Since then, I’ve managed to get cmdstan to build on my Windows machine, and have found out the following. I’m posting it here in the hope it might help some one.

My original attempt used the latest version of Rtools, version 4.0. In my case, this required me to add the following directories to the path before running make build:

C:\Rtools40\usr\bin
C:\Rtools40\mingw64\bin

My original problem was that the Intel TBB library would not build, with the following error message:

ERROR: Please use mingw32-make on Windows to build the Intel TBB library.

The problem arises from the fact that the latest version of RTools, 4.0, does not include an exe called mingw32-make.exe. This seems to have been renamed make.exe. I tried duplicating make.exe from Rtools to mingw32-make.exe, and ran mingw32-make build, which still failed with an obscure error message:

mingw32-make[1]: Entering directory ‘/c/Users/ajs/OneDrive/ajs/dev/cmdstan/stan/lib/stan_math/lib/tbb’
‘“cscript /nologo /E:jscript …/tbb_2019_U8/build/detect.js /arch gcc”"’ is not recognized as an internal or external command, operable program or batch file.
‘“cscript /nologo /E:jscript …/tbb_2019_U8/build/detect.js /runtime gcc”"’ is not recognized as an internal or external command, operable program or batch file.
…/tbb_2019_U8/build/common.inc:81: *** Architecture not detected. Stop.
mingw32-make[1]: Leaving directory ‘/c/Users/ajs/OneDrive/ajs/dev/cmdstan/stan/lib/stan_math/lib/tbb’
mingw32-make: *** [stan/lib/stan_math/make/libraries:173: stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 2.

What finally worked for me was to install mingw directly from here:

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download

This will download an exe which you need to run to install mingw64. On the Settings screen, there is a drop down box labelled “Architecture” which defaults to i686. On a 64 bit machine you need to change the value to x86_64. On the next screen, the install directory defaults to:

C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0

Do not accept this default. If you do, the cmdstan build process will fail later on the grounds that there are spaces in the Rtools path, even though you are no longer using RTools. On my machine, I opted to install to c:\mingw64

Once the installation has completed, add the following (or equivalent, depending where you installed mingw64) to your path:

C:\mingw4\mingw64\bin

Open up a command shell. For me, the Windows command shell fails, again with obscure error messages:

C:\Users\ajs\OneDrive\ajs\dev\cmdstan>mingw32-make build

‘cut’ is not recognized as an internal or external command,operable program or batch file.
‘cut’ is not recognized as an internal or external command,operable program or batch file.
INFO: Could not find files for the given pattern(s).
The syntax of the command is incorrect.
mingw32-make: *** [stan/lib/stan_math/make/libraries:172: stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 1

So, I opened up a git bash shell. Cd to the cmdstan directory – eg:

cd /c/users/ajs/OneDrive/ajs/dev/cmdstan/

and run mingw32-make build. Worked for me.

One final issue. If you try to build the sample like this:
mingw32-make examples/bernoulli/bernoulli

you may get the following error:
mingw32-make: *** No rule to make target ‘examples/bernoulli/bernoulli’. Stop.

Try:
mingw32-make examples/bernoulli/bernoulli.exe

Hope this helps some one.

Hi, once you install RTools 4 and add correct folders to the PATH (remember to close cmd and open new cmd) then you need to install mingw32-make (it is not renamed)

E.g.

pacman -Sy mingw-w64-x86_64-make --noconfirm
1 Like

thanks for this report - it is most useful!
just to let you know, you’ve definitely been heard and
there’s a lot of discussion among some of the Stan and Julia devs
scripting/packaging the toolchain installers.

Thanks. I was not aware of that way of doing it. I found that the mingw-64 installation on Sourceforge also works fine for me so far without needing Rtools.

Also, I think cut is not needed in 2.26 anymore, which will make it easier to use non-rtools mingw.

1 Like