Issue compiling bernoulli example model in cmdstan 2.17


Operating System: Fedora 26 (kernel 4.13)
Interface Version: 2.17.0
Compiler/Toolkit: gcc 7.2.1

Hi everyone,

I’m a reasonably experienced user of pystan but to resolve some compatibility issues I’m trying to switch some of my work over to cmdstan.

I’ve built all the submodules and run the tests with the “” script without any issues, however upon trying to run the bernoulli example I’m receiving an error.

I run:

make examples/bernoulli/bernoulli

from the cmdstan base directory and receive an error from (I think?) gcc:

cc1plus: fatal error: -pch: No such file or directory

This occurs during linking the c++ model, at which point the compilation is terminated.

Any advice on how to troubleshoot this would be appreciated - I’ve had a quick search but have found nothing helpful so far.


Can you post the entire compiler invocation, starting with the line beginning with g++/clang++


Of course - silly of me not to have posted this before:

make examples/bernoulli/bernoulli

— Linking C++ model —
g++ -Wall -I . -isystem stan/lib/stan_math/lib/eigen_3.3.3 -isystem stan/lib/stan_math/lib/boost_1.64.0 -isystem stan/lib/stan_math/lib/cvodes_2.9.0/include -std=c++1y -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -Wno-unused-function -Wno-uninitialized -I src -I stan/src -isystem stan/lib/stan_math/ -DEIGEN_NO_DEBUG -DFUSION_MAX_VECTOR_SIZE=12 -DNO_FPRINTF_OUTPUT -pipe -lpthread -include-pch stan/src/stan/model/model_header.hpp.gch -O3 -o examples/bernoulli/bernoulli src/cmdstan/main.cpp -include examples/bernoulli/bernoulli.hpp stan/lib/stan_math/lib/cvodes_2.9.0/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/cvodes_2.9.0/lib/libsundials_cvodes.a
cc1plus: fatal error: -pch: No such file or directory
compilation terminated.
make: *** [make/models:16: examples/bernoulli/bernoulli] Error 1


This is a makefile bug. @seantalts @syclik just pinging you so you see this.

clang++ uses the -include-pch flag but g++ just includes precompiled headers automatically if they are in the same directory as the original header. So here g++ is interpreting -include-pch as the -include flag with -pch as the value so it can’t find the file called -pch.

For Daniel and Sean: This would all be much easier to resolve if we didn’t have to have pull so much makefile magic from the math lib. Could we just make separate makefiles for CmdStan and only pull the really generic ones from the math lib like identifying compiler and os?


This bug is what my PR from Nov 8 fixes:

I recently intentionally refactored the makefiles to share more code and settings because there was a ton of duplication. Maybe I went too far, though I don’t think this bug speaks to that question in either direction as its just in the CmdStan makefile and doesn’t have anything to do with the Stan or Math repo makefiles the CmdStan repo includes.


@sakrejda, thanks. I missed the first message.

I think this was the cause of it. It was the right thing to do… I don’t think we realized how far-reaching the effects would be. I’ll take action to walk through the makefiles before releasing the next CmdStan version. Hopefully this week.

I haven’t had a chance to test that it works. I think for these makefile fixes, we should be making sure it compiles against Win, Mac, and Linux. I know we have all three at Columbia, so I’ll try running it there before approving.


Thanks Sean, I didn’t want it to get missed.


Thanks for the explanation everyone -

Is there a fix I can implement immediately or should I wait for a patch?

(apologies if this is obvious)


If you don’t mind editing the makefiles you can find the -include-pch flag in there and remove it (and whatever was getting included like that). Or you can clone cmdstan develop which (I think) has this fixed.


I’ll try cloning the development version.

Thanks once again!


2.17.1 is also out now in case that helps.