12

I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it.

#ifdef _WIN32
#include "stdafx.h"
#elif _MAC
#include "MAC/stdafx.h"
#endif

You may wonder why I am using stdafx.h in the Mac code, but that is not important at the moment :).

When I try to compile the code on Windows, I receive: Fatal Error C1018. I tried enclosing other header files with #ifdef in the same file, and the compiler was happy. Therefore, it looks like Windows doesn't like stdafx.h to be #ifdef-ed, or that Windows only allows #include stdafx.h to be the first line in the file.

So my question is, why?

Kat

kyue
  • 143
  • 3
  • 8

2 Answers2

10

When the compiler includes a pre-compiled header, it basically "forgets" anything that came before the header. Thus your #elif isn't matched to a #if anymore.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
6

This is because you have Precompiled Headers turned on - turn it off and you should be fine.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209