0

I have unit a.cpp that is used in several projects in subdirectory libA. Some of project are using precompiled headers, while others -not. In this case projects that use precompiled header must have line:

#include <stdafx.h>

and projects that are not using PCH must have line:

#include "..\stdafx.h"

Wise verse is not working.

Why project sees stdafx.h file in different way when project uses PCH or not?

UPD.

When I replace line #include <stdafx.h> with #include "..\stdafx.h" in project that uses precompiled header i have error

Error   19  error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Directory structure is the same in both projects.

vico
  • 17,051
  • 45
  • 159
  • 315
  • A different solution: put a.cpp into a library or DLL for re-use. Then you don't need to worry about precompiled header differences. – crashmstr Jan 05 '15 at 15:33
  • This might be solution, but I'm lazy to recompile libs in separate project each time I change them. And it is not nice :) – vico Jan 05 '15 at 15:39
  • Add the library or DLL project to your other solutions and add a dependency. Once it is set up, no extra work needed! It *is* nice. Reused code belongs in libraries or DLLs. – crashmstr Jan 05 '15 at 15:40
  • Does this answer your question? [What is the difference between #include and #include "filename"?](https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename) – Makonede Feb 22 '22 at 17:31

1 Answers1

0

There is no (or there should not be any) difference between <stdafx.h> and "stdafx.h". The only significant difference is that one project "sees" the file in current folder, and the other project sees it in parent folder. This difference is controlled by compiler option Additional Include Directories. One project has libA in it, and the other does not have it.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • Both projects has line .\libA\ in Additionl Include Directories. And both of them has a.cpp in these directories – vico Jan 05 '15 at 15:36
  • @vico I got it wrong. Projects need path to `stdafx.h`, not to `libA`. So, one project has that directory (could be as simple as `.`, or maybe `$(ProjectDir)` or `$(SolutionDir)`), and the other does not have it. – Dialecticus Jan 05 '15 at 16:04
  • Both projects has the same lines in Additional Include Directories. – vico Jan 05 '15 at 16:31