Вопрос

It seems that when I set the option to /Yu, it just uses whatever pch there is, without checking if it needs to be updated, meaning it would keep a list of headers it precompiles and check if those files has been updated since the last time they have been precompiled.

But when I /Yc, it just re-precompiles each time I build my project.

I'm not very sure if visual C++ handles those behaviors as good as I think, or if I'm making the mistake of editing a .h file or else.

So should I set /Yc, build, reset to /Yu, keep iterating, but reset to /Yc, rebuild, and then RESET to /YU each time I update a header ?

Это было полезно?

Решение

You set one file that includes your header that you want precompiling to use /Yc, and that will generate the pch file if necessary (i.e., the pch file is out of date relative to the header). Then set the other files that include it to use /Yu, and they use the precompiled header that your first file generates.

If you use the Visual Studio wizard to generate a console project with a precompiled header, you'll see this in action. The stdafx.cpp file includes stdafx.h, and has /Yc set to generate a pch file for it; then the main.cpp file includes stdafx.h too, but it has /Yu set, so it uses the pch file.

(I found the precompiled header section of the documentation a bit opaque at first, but once I'd got precompiled headers set up and I'd seen them working, it started to make a bit more sense.)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top