Question

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.

Was it helpful?

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.

OTHER TIPS

Delete the derived data (Window-Organizer, Projects tab, select your project) to have XCode rebuild the index for PCH's. Also, if you use Unit Tests, there is a separate PCH for the UnitTests target. Make sure this also includes the required imports.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top