Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using /YC and /MP together in a Visual Studio 10 project

I'm trying to get around the limitation of /YC and /MP being mutually exclusive. I'd like to leverage precompiled headers AND multi-process compilation.

My answer so far has been to create 2 projects instead of 1. The first is a pch generating library consisting of just an stdafx.h and stdafx.cpp. It generates the pch file with /YC set on the stdafx.cpp

That library generates the pch file successfully! As a side note, the pch library project also has /YU specified pointing to its stdafx.h and /Fp referencing the output pch file.

My second project is my main executable. It has /MP specified but does not have /YC specified for any file and does not contain an stdafx.h or stdafx.cpp. Instead I set the project's /YU to the stdafx.h of the pch library and /Fp to the pch generated by the pch library. I then set the pch library as a dependency of the exe project. I also set /FI on the exe project to forcibly include the stdafx.h from the pch library in each compilation unit.

My problem is that, while the pch library DOES generate the pch file and the exe project does seem to reference the generated pch file correctly, as soon as the exe project starts to build (after some pre-build steps unrelated to the pch), it DELETES the pch generated by the pch library. I imagine it's because it thinks, with /Fp is specified, that the project will generate that file even though there are no /YC's specified.

Is there something I'm doing wrong here? Am I missing a step. Is there a way to prevent the exe project from deleting my pch file before it starts building?

Any help would be greatly appreciated!

like image 235
cppguy Avatar asked Feb 09 '13 00:02

cppguy


1 Answers

Try this: Does visual C++ check if it needs to re-generate its pch if I use /Yc

You basically set /Yc for stdafx.cpp, and /Yu + /MP for all the other *.cpp files.

To set flags seperatelly for each file, right-click a cpp file on your Solution Explorer and select Properties.

like image 169
mage_hat Avatar answered Oct 27 '22 09:10

mage_hat