Does visual C++ check if it needs to re-generate its pch if I use /Yc
Asked Answered
W

1

-1

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 ?

Winifield answered 25/8, 2012 at 11:51 Comment(2)
I hope my english is good enough and that I explained my problem in a good mannerWinifield
possible duplicate of How to use precompiled headers efficiently (using /Yc and Yu options)?Corvette
B
0

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.)

Bushcraft answered 25/8, 2012 at 12:23 Comment(5)
how do you "set" /yc or /yu on individual files ? When I asked I essentially meant in the project properties...Winifield
Select file(s) in the solution explorer, then right click and select the Properties option from the context menu. You can use this to set certain options on a per-file basis. The precompiled header options are one such option.Bushcraft
can you confirm I can do the same for multiple files at once ? (I'm not on a windows atm)Winifield
Yes, you can. Though you're best off setting the usual case (/Yu) in the project settings, then changing the file settings for the file that is the unusual case (the /Yc one). Files use the project settings unless specifically set.Bushcraft
I can't find this option in MSVC 2010Winifield

© 2022 - 2024 — McMap. All rights reserved.