3

If /Yu is set for an individual cpp file (i.e. not for an entire project) is it possible to set /FI to specify the header file to be included or must the header file be included with for example #include "stdafx.h" if /Yu"stdafx.h" is passed to CL?

All the following result in basically the same error...

With a header at C:\path\to\stdafx.h and test.cpp like so...

// Not including `stdafx.h`
void foo() {}

And any one of these to compile...

CL.exe /c /Yu"stdafx.h" /FI"C:\path\to\stdafx.h" test.cpp
CL.exe /c /Yu /FI"C:\path\to\stdafx.h" test.cpp
CL.exe /c /Yustdafx.h /FIC:\path\to\stdafx.h test.cpp
CL.exe /c /Yu /FIC:\path\to\stdafx.h test.cpp

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

It seems to me that it should be possible to use /FI to specify the precompiled header.

This answer seems to suggest it is even the preferred method https://stackoverflow.com/a/11052390/6225135

Johnny Haddock
  • 415
  • 3
  • 11
  • More answers that suggest it works: https://stackoverflow.com/a/11403418/15416. @VTT: `/FI` is described as an implicit `#include` – MSalters Dec 11 '17 at 11:30
  • Might the problem be that `stdafx.h` is _not_ `C:\path\to\stdafx.h` ? IOW, the problem might be that VC++ does a string compare, rather than trying to decide whether both names would refer to the same file. – MSalters Dec 11 '17 at 11:32
  • Yes that is it exactly, @MSalters I had `/Yu"stdafx.h"` and `/FI"C:\full\path\to\stdafx.h"` which is a no-no Even if they are equivalent they must be identical. If you reply with that I will accept it as the answer. Thanks! – Johnny Haddock Dec 11 '17 at 11:50

2 Answers2

2

The problem is that stdafx.h is not C:\path\to\stdafx.h. VC++ does a string compare. You'd need to add C:\path\to\ to the include path, so you can use just /FI"stdafx.h"

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

After some experiments I've managed to make it work properly. Turned out all I had to do is to supply the same value as for /Yu

/FI"stdafx.h"
user7860670
  • 35,849
  • 4
  • 58
  • 84