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

Hello,

I am having the same problem as you however, the installer of mingw64 doesn’t work, I have been told that “The file has been download incorrectly”.

Thus, I went on the following page to see how to fixed it. I downloaded Mingw64 manually and put it into a folder, but when I did not find the mingw64/bin path so I could not add it to my PATH.

Does someone have encounter this problem and have ideas on how to solve it ?

Thank you very much for your help,

Stan

The error messaged I got on the git bash was :

curl -L https://github.com/stan-dev/stanc3/releases/download/nightly/windows-stanc -o bin/stanc.exe --retry 5 --retry-delay 10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   652  100   652    0     0   3607      0 --:--:-- --:--:-- --:--:--  3662
100 22.0M  100 22.0M    0     0  9482k      0  0:00:02  0:00:02 --:--:-- 11.5M
g++ -pipe   -m64 -D_REENTRANT  -O3 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DNO_FPRINTF_OUTPUT   -D_USE_MATH_DEFINES  -O3  -c -x c -include stan/lib/stan_math/lib/sundials_6.1.1/include/stan_sundials_printf_override.hpp stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.c -o stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o
stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.c:1:0: sorry, unimplemented: 64-bit mode not compiled in
 /* -----------------------------------------------------------------

stan/lib/stan_math/make/libraries:63: recipe for target 'stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o' failed
mingw32-make: *** [stan/lib/stan_math/lib/sundials_6.1.1/src/nvector/serial/nvector_serial.o] Error 1

[note : the French sentence means “impossible to find files fot he specified models”]

Can anyone look at this? I tried to help but I lack experience with windows .

@rok_cesnovar @mitzimorris @yizhang

Hi @Stan_dC,

I am not sure about this mingw64 toolchain. If possible I would uninstall it and try with the RTools supported toolchain. It’s what we recommend and know that works.

  • step 1: Using Rtools4 on Windows install the 64-bit one. If possible, install it in the default location, which should be C:/Rtools40

  • step 2: add

C:\RTools40\usr\bin
C:\RTools40\mingw64\bin

to the PATH variable. Make sure to add it at the top (start). If you need help on how to do that, have a look here.

  • step 3:

open a fresh Powershell window (opened after you ran step2) and run

pacman -Sy mingw-w64-x86_64-make

This last step will install the missing mingw32-make. That should be it. Let me know if you need any additional help.

1 Like

hi @rok_cesnovar ,
Thank you for your quick answer. I did all the steps you recommend. and I still have the following error :

ar: création de stan/lib/stan_math/lib/sundials_6.0.0/lib/libsundials_idas.a
ar -rs stan/lib/stan_math/lib/sundials_6.0.0/lib/libsundials_kinsol.a stan/lib/stan_math/lib/sundials_6.0.0/src/kinsol/kinsol_io.o stan/lib/stan_math/lib/sundials_6.0.0/src/kinsol/kinsol_spils.o stan/lib/stan_math/lib/sundials_6.0.0/src/kinsol/kinsol_ls.o stan/lib/stan_math/lib/sundials_6.0.0/src/kinsol/kinsol.o stan/lib/stan_math/lib/sundials_6.0.0/src/kinsol/kinsol_bbdpre.o stan/lib/stan_math/lib/sundials_6.0.0/src/kinsol/kinsol_direct.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_dense.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_nvector_senswrapper.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_nvector.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_context.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_memory.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_math.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_linearsolver.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_iterative.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_direct.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_band.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_version.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_nonlinearsolver.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_futils.o stan/lib/stan_math/lib/sundials_6.0.0/src/sundials/sundials_matrix.o stan/lib/stan_math/lib/sundials_6.0.0/src/sunmatrix/band/sunmatrix_band.o stan/lib/stan_math/lib/sundials_6.0.0/src/sunmatrix/dense/sunmatrix_dense.o stan/lib/stan_math/lib/sundials_6.0.0/src/sunlinsol/band/sunlinsol_band.o stan/lib/stan_math/lib/sundials_6.0.0/src/sunlinsol/dense/sunlinsol_dense.o stan/lib/stan_math/lib/sundials_6.0.0/src/sunnonlinsol/newton/sunnonlinsol_newton.o stan/lib/stan_math/lib/sundials_6.0.0/src/sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.o
ar: création de stan/lib/stan_math/lib/sundials_6.0.0/lib/libsundials_kinsol.a
tbb_root="../tbb_2020.3" CXX="g++" CC="gcc" LDFLAGS='-Wl,-L,"C:/Users/stanislas/Documents/.cmdstan/cmdstan-2.29.2/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"C:/Users/stanislas/Documents/.cmdstan/cmdstan-2.29.2/stan/lib/stan_math/lib/tbb"  ' 'mingw32-make.exe' -C "stan/lib/stan_math/lib/tbb" -r -f "C:/Users/stanislas/Documents/.cmdstan/cmdstan-2.29.2/stan/lib/stan_math/lib/tbb_2020.3/build/Makefile.tbbmalloc" compiler=gcc cfg=release stdver=c++1y malloc CXXFLAGS="-Wno-unknown-warning-option -Wno-deprecated-copy -Wno-missing-attributes -Wno-class-memaccess -Wno-sized-deallocation  "
mingw32-make[1]: Entering directory 'C:/Users/stanislas/Documents/.cmdstan/cmdstan-2.29.2/stan/lib/stan_math/lib/tbb'
'cscript' n'est pas reconnu en tant que commande interne
ou externe, un programme ex‚cutable ou un fichier de commandes.
mingw32-make[1]: Leaving directory 'C:/Users/stanislas/Documents/.cmdstan/cmdstan-2.29.2/stan/lib/stan_math/lib/tbb'
'cscript' n'est pas reconnu en tant que commande interne
ou externe, un programme ex‚cutable ou un fichier de commandes.
../tbb_2020.3/build/common.inc:81: *** Architecture not detected.  Stop.
mingw32-make.exe: *** [stan/lib/stan_math/make/libraries:173: stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 2
mingw32-make.exe: *** Waiting for unfinished jobs....
Warning message:
There was a problem during installation. See the error message(s) above.

[note : the french text means : “‘csript’ is not recognised as a internal or external command”]

Can you runt he following 4 commands in Powershell:

g++ --version
Get-Command g++ | Select-Object -ExpandProperty Definition
mingw32-make --version
Get-Command mingw32-make | Select-Object -ExpandProperty Definition

and paste the output. Thanks!

please find attached a screenshot of the outputs.

here is a screenshot of my path variables

It looks like you are using the command line where the lines of code rok asked you to run need to be run via powershell, which is a different sort of terminal interface which supports the commands listed above

1 Like

It’s concerning to me that it seems like MingGW is on your PATH in more than one place.

An alternative I mentioned during the Stan meeting today is Conda, which works by “environments” which set up all of this for you.

If you want to do that, you can install it from here

Then open any terminal (though @stevebronder is right, powershell is generally better than cmd.exe) and you should be able to run

conda create -n stan cmdstan r-base

After than runs, you can run conda activate stan to activate this environment, and then run R etc. This will create a parallel copy of R, so you will need to re-installed cmdstanr etc, though you can just use the standard commands from within R to do that.

The bonus here is that cmdstan is pre-compiled and guaranteed to have the required software packaged with it, so you don’t run into any of those issues.

2 Likes

here is the result in a powershell

image

I tried to install via conda.
I installed without problems the environment and open a R session directly on anaconda prompt. However, when I tried install_cmdstan(), I still find the same problems.

I had the following errors.


Uploading: image.png(1)…

There is no need to run install_cmdstan if you go the conda route

3 Likes

Work nowww !!! Thank you so much ! I owe you one !!

2 Likes