0

I have code that is used across platforms (Windows and Linux). In windows the code uses precompiled headers so I include stdafx.h but in linux I don't. So I have this at the top of every .cpp file:

#ifdef WIN32
#include "stdafx.h"
#endif // WIN32  // compiler error here

This compiles fine on linux but in Visual Studio 2013 I get the compiler error:

Error 2 error C1020: unexpected #endif

I think it is because stdafx.h contains a #pragma once macro.

How can I fix this and is there a better way to make the code cross-platform?

sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

2

This error you are getting because compiler completely ignores everything written before precompiled header. You can put desired thing in stdafx.h instead of conditional include of precompiled header.

Also please see this link https://connect.microsoft.com/VisualStudio/feedback/details/506745/visual-studio-2008-c-fatal-error-c1020-unexpected-endif

Vinod
  • 115
  • 11