3

Visual Studio C++ lib project Project is set to use precompiled headers stdafx.cpp is set to create precompiled header

I have a header file, MyClass.h If I build, then make a change to MyClass.h that should fail to compile, compile still succeeds. If I do a rebuild, or if I make a change to a cpp file that includes "MyClass.h", then the compile fails as expected.

Is this expected because I'm using precompiled headers? Is there any way to fix it so a 2nds buid picks up header changes without turning off precompiled headers?

cpp dev
  • 163
  • 1
  • 5

4 Answers4

3

Make sure that the header file you are altering is referenced by your project in Solution Explorer. If this is the case, the full build should trigger when it is changed.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • Well, seems like it might not be the cause from his comments (I'm not sure what the option "Enable Minimal Rebuild" do exactly) but this is a frequent problem that has the same symptoms: +1. – n1ckp Nov 03 '10 at 17:46
2

In the project properties, set "Enable Minimal Rebuild" to No

cpp dev
  • 163
  • 1
  • 5
  • I had the same problem as the original poster as changed to .H files would not get picked up for compilation, both with and without precompiled headers. Disabling minimal rebuilds fixed this major annoyance for me. Thank you. – Eric Fortier Jan 04 '13 at 07:04
0

Are you sure that stdafx.cpp includes the header in question?

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
0

VisualStudio can often get pretty damn stupid over changes. It can go either way, but usually it goes the way you're running into.

I've had it catch onto changes in a header used by one file, but not the fact that it's used in others. So it compiles the one but not the others. Then I get really weird linker errors.

It could of course still be your own damn fault, but VS is, in fact, notoriously stupid. Sometimes a complete rebuild will fix the issue permanently, until next time. Other times you have somehow hosed the project file and hopefully you can get back to the original (like a source server revert). "Undo" most usually does not undo this kind of fubar.

I've noted this several times not needing to be a header that's in the precompiled header. It seems to be somewhat random but one more common correlation is that the header is full of templates. VS is just plain retarded wrt templates.

Edward Strange
  • 40,307
  • 7
  • 73
  • 125