Trouble building the Bernoulli example (Windows 10, cmdstan 2.19.1)

Hi, I’m new to Stan and am trying to follow the cmdstan-guide-2.19.1.pdf tutorial (actually want to use MatlabStan but there seems to be an underlying problem compiling the stan file).

I managed to build CmdStan successfully (as far as I can tell) but got the following error when I tried to compile bernoulli.stan:

C:\Users\<username>\Documents\cmdstan-2.19.1>make examples/bernoulli/bernoulli.exe
g++ -std=c++1y -m64 -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs     -O3 -I src -I stan/src -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include  -D_USE_MATH_DEFINES  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION     -c -MT  -MT examples/bernoulli/bernoulli.exe -include examples/bernoulli/bernoulli.hpp -include src/cmdstan/main.cpp -M -E -MG -MP -MF examples/bernoulli/bernoulli.d examples/bernoulli/bernoulli.hpp
g++.exe: error: examples/bernoulli/bernoulli.exe: No such file or directory
make: *** [examples/bernoulli/bernoulli.d] Error 1

The examples/bernoulli directory contains these files:
bernoulli.data.R bernoulli.data.json bernoulli.hpp bernoulli.stan

I don’t understand why g++ is looking for bernoulli.exe – I thought this step was supposed to create that from the stan file. Am I doing something wrong? Any help fixing this problem would be greatly appreciated.

Please provide this additional information in addition to your question:

  • Operating System: Windows 10
  • CmdStan Version: 2.19.1
  • Compiler/Toolkit: gcc version 4.9.3 (x86_64-posix-seh, Built by MinGW-W64 project) / Rtools 3.4

What is the output of make help?

C:\Users<username>\Documents\cmdstan-2.19.1>make help

CmdStan v2.19.1 help

Build CmdStan utilities:
> make build

This target will:
1. Build the Stan compiler bin/stanc.exe.
2. Build the print utility bin/print.exe (deprecated; will be removed in v3.0)
3. Build the stansummary utility bin/stansummary.exe
4. Build the diagnose utility bin/diagnose.exe

Note: to build using multiple cores, use the -j option to make.
For 4 cores:
> make build -j4

Build a Stan program:

Given a Stan program at foo/bar.stan, build an executable by typing:
> make foo/bar.exe

This target will:
1. Build the Stan compiler and the print utility if not built.
2. Use the Stan compiler to generate C++ code, foo/bar.hpp.
3. Compile the C++ code using gcc . to generate foo/bar.exe

Additional make options:
STANCFLAGS: defaults to “”. These are extra options passed to bin/stanc.exe
when generating C++ code. If you want to allow undefined functions in the
Stan program, either add this to make/local or the command line:
STANCFLAGS = --allow_undefined
USER_HEADER: when STANCFLAGS has --allow_undefined, this is the name of the
header file that is included. This defaults to “user_header.hpp” in the
directory of the Stan program.

Example - bernoulli model: examples/bernoulli/bernoulli.stan

1. Build the model:
   > make examples/bernoulli/bernoulli.exe
2. Run the model:
   > examples\bernoulli\bernoulli.exe sample data file=examples/bernoulli/bernoulli.data.R
3. Look at the samples:
   > bin\stansummary.exe output.csv

Clean CmdStan:

Remove the built CmdStan tools:
> make clean-all

I get slightly different instructions:

  Example - bernoulli model: examples/bernoulli/bernoulli.stan

    1. Build the model:
       > make examples/bernoulli/bernoulli
    2. Run the model:
       > examples/bernoulli/bernoulli sample data file=examples/bernoulli/bernoulli.data.R
    3. Look at the samples:
       > bin/stansummary output.csv

Are you on Windows?

You tried the Windows version of the make without the .exe?

I tried with .exe (Also without, but that gives me make: *** No rule to make target examples/bernoulli/bernoulli'. Stop.).

You’ve run make stan-update at some point since downloading?

Long shot: do you have spaces somewhere in your abspath?

No, I haven’t.

Don’t think so… None of the directories above cmdstan has any spaces in its name.

Is upgrading to at least RTools 3.5 an option?

1 Like

Bingo. I replaced Rtools 3.4 with 3.5 and somehow everything worked. Thank you!

Does RTools 3.4 support C++14?

Rtools 3.4 should have gcc 4.9.3 that supports all C++14 features as far as I know. It might be just the reinstall itself that helped. I suggested 3.5 as that is what I am running on my Windows testing machine and it works as expected.

2 Likes