Search code examples
c++xcodeprecompiled-headerspch

Xcode PCH issue - Items in PCH Not Included in Source Files


I just created a "C++ Standard Dynamic" library project using Xcode and compiled using LLVM 2.0. I notice that the PCH file contains the line #include <iostream> but the file Test.cp also includes that #include <iostream> statement.

The strange thing is that by removing the statement in Test.cp, the build fails with the error Semantic Issue – Use of undeclared identifier 'std' despite the fact that that statement is also included in the PCH.

Why doesn't the PCH work? Is there a setting I'm missing? I've never done anything with them before (since they always just work) so I'm not sure what's causing it not to work, even with a brand-new project.


Solution

  • Precompiled headers are used for speeding up compilation. They don't have any other effect, in particular you still have to include the headers where you need them.

    Edit - In Xcode the pch file is really a prefix header that happens to be precompiled (with the default project configuration). Check the GCC_PRECOMPILE_PREFIX_HEADER and GCC_PREFIX_HEADER build settings.