문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top