How to fix PCH conflict error building CmdStan, CmdStanPy, or CmdStanR

If you update your C++ compiler, then you need to clear out the old precompiled headers (PCH) files that are generated. Otherwise, you will get a warning that looks something like this:

error: PCH file built from a different branch ((clang-1316.
than the compiler ((clang-1400.0.29.102))

The reason for the error is that the compiler is caching partial compilation results, but that cache breaks if the compiler is updated without manually clearing out the cache. We haven’t been able to figure out how to automate instructions on how to fix because clang keeps changing the wording of the error message.

The easiest way to solve this problem is to clean all in a terminal. This can be done as follows, where <cmdstan> is the path to the top-level directory in which cmdstan is installed:

$ cd <cmdstan>
$ make clean-all
1 Like

Thanks @Bob_Carpenter. I would just add that with, cmdstanr, the simplest solution is to call cmdstanr::rebuild_cmdstan().

Thanks, @rok_cesnovar. Didn’t cmdstanr figure out how to actually suggest that? I see that cmdstanpy has a function install_cmdstan, but I don’t know if that would’ve worked. In any case, I was just inside of cmdstan itself at this point, as I don’t like having to debug through interfaces.

1 Like

Yes, cmdstanr will suggest rebuilding with rebuild_cmdstan() in case “PCH” is mentioned in the C++ compiler error message.