-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 ?

jokoon
  • 6,207
  • 11
  • 48
  • 85
  • I hope my english is good enough and that I explained my problem in a good manner – jokoon Aug 25 '12 at 11:54
  • possible duplicate of [How to use precompiled headers efficiently (using /Yc and Yu options)?](http://stackoverflow.com/questions/5177046/how-to-use-precompiled-headers-efficiently-using-yc-and-yu-options) – Bo Persson Aug 25 '12 at 12:04

1 Answers1

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

Tom Seddon
  • 2,648
  • 1
  • 19
  • 28
  • how do you "set" /yc or /yu on individual files ? When I asked I essentially meant in the project properties... – jokoon Aug 25 '12 at 13:10
  • 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. – Tom Seddon Aug 25 '12 at 22:56
  • can you confirm I can do the same for multiple files at once ? (I'm not on a windows atm) – jokoon Aug 26 '12 at 14:10
  • 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. – Tom Seddon Aug 26 '12 at 23:05
  • I can't find this option in MSVC 2010 – jokoon Sep 04 '12 at 14:13