# PCH + gcc: sccache fails, ccache succeeds

**URL:** https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615
**Category:** Usage
**Created:** [July 27, 2023, 6:47am UTC](https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615 "2023-07-27T06:47:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 27, 2023, 6:47am UTC](https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615/1 "2023-07-27T06:47:34Z")

</div>

I discovered today that if using gcc with precompiled headers, using sccache fails but ccache works. It appears that sccache doesn’t properly handle the PCH artifacts, resulting in errors of the form:

```auto
cc1plus: error: /some/path/cmake_pch.hxx.gch: not a PCH file

```

even though that file does exist and was created by gcc, so it’s presumably a valid PCH file.

@ben.boeckel reported sccache not supporting PCH years ago in [Does not support PCH compilation using `-include` · Issue #615 · mozilla/sccache · GitHub](https://github.com/mozilla/sccache/issues/615), which is still an open issue, but I don’t know if it is essentially the same lack of support, just a different manifestation of what I’m seeing. Anyone have any further details on this particular combination and whether it’s likely to be fixed any time soon? I was surprised by how little there seems to be online about it, given that it makes sccache a non-starter for any project using gcc with precompiled headers. For CMake projects, I’d expect that to be a common enough combination that we should be seeing more bug reports and discussions about it, so maybe I’m missing some important detail.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 27, 2023, 7:25am UTC](https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615/2 "2023-07-27T07:25:42Z")

</div>

Strangely, it seems that sccache _does_ handle clang + PCH.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 27, 2023, 10:05am UTC](https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615/3 "2023-07-27T10:05:06Z")

</div>

I think PCH usage is actually way lower in practice. But it seems that GCC’s `-include` usage for PCH is different enough from Clang’s. `-include` is seen as a preprocessor argument, but is needed for the compile with GCC"s PCH. How does Clang do PCH?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 28, 2023, 3:46am UTC](https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615/4 "2023-07-28T03:46:18Z")

</div>

> [@ben.boeckel](#):
>
> How does Clang do PCH?

I don’t know the details, but maybe @cristianadam does (he implemented the PCH feature, from what I recall).

---

<div class="post-metadata">

### Author: ![cristianadam](https://discourse.cmake.org/user_avatar/discourse.cmake.org/cristianadam/32/124_2.png) [@cristianadam](https://discourse.cmake.org/u/cristianadam)
#### Post date: [July 28, 2023, 11:02am UTC](https://discourse.cmake.org/t/pch-gcc-sccache-fails-ccache-succeeds/8615/5 "2023-07-28T11:02:22Z")

</div>

This is how [GCC](https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Compiler/GNU.cmake#L187) does PCH, and how [Clang](https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Compiler/Clang.cmake#L116) does it.

I think people do not complain about it because the usual combination is cache without PCH. This is how Qt does it.

[Here](https://ccache.dev/manual/4.8.2.html#_precompiled_headers) is the ccache manual documentation about PCH.

I personally prefer ccache as seen at [gitlab-ci: consider using ccache instead of sccache (#23877) · Issues · CMake / CMake · GitLab (kitware.com)](https://gitlab.kitware.com/cmake/cmake/-/issues/23877) 🙂
