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

**URL:** <https://discourse.mc-stan.org/t/how-to-fix-pch-conflict-error-building-cmdstan-cmdstanpy-or-cmdstanr/28895>\
**Category:** General\
**Created:** [September 20, 2022, 7:10pm UTC](https://discourse.mc-stan.org/t/how-to-fix-pch-conflict-error-building-cmdstan-cmdstanpy-or-cmdstanr/28895 "2022-09-20T19:10:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [September 20, 2022, 7:10pm UTC](https://discourse.mc-stan.org/t/how-to-fix-pch-conflict-error-building-cmdstan-cmdstanpy-or-cmdstanr/28895/1 "2022-09-20T19:10:57Z")

</div>

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:

```nohighlight
error: PCH file built from a different branch ((clang-1316.0.21.2.5))
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:

```nohighlight
$ cd <cmdstan>
$ make clean-all

```

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [September 20, 2022, 7:30pm UTC](https://discourse.mc-stan.org/t/how-to-fix-pch-conflict-error-building-cmdstan-cmdstanpy-or-cmdstanr/28895/2 "2022-09-20T19:30:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [September 20, 2022, 7:55pm UTC](https://discourse.mc-stan.org/t/how-to-fix-pch-conflict-error-building-cmdstan-cmdstanpy-or-cmdstanr/28895/3 "2022-09-20T19:55:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [September 20, 2022, 8:00pm UTC](https://discourse.mc-stan.org/t/how-to-fix-pch-conflict-error-building-cmdstan-cmdstanpy-or-cmdstanr/28895/4 "2022-09-20T20:00:24Z")

</div>

> [@Bob\_Carpenter](#):
>
> Didn’t cmdstanr figure out how to actually suggest that?

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