1
votes

I'm trying to compile a SWIG project, and it keeps on giving errors like this:

swig_wrap.cpp(55): warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro redefinition

And errors like this:

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

Compiler

  • Visual Studio 2015+Update 3.
  • SWIG v3.0.12
2

2 Answers

2
votes

Add the following to your .i file:

%begin %{
#include "stdafx.h"
%}

This section injects code into the generated wrapper at the top of the file and you won't need to disable pre-compiled headers.

1
votes

In Visual Studio, right click on the swig-generated .cpp wrapper file, and select "Not Using Precompiled Headers".

In my case, the wrapper file that swig auto-generated was swig_wrap.cpp.

You can leave precompiled headers on for the entire project.

For more info, see nabble.com and Fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

enter image description here


Appendix A: SWIG could be fixed to avoid this!

Another way to fix this is to manually add the line "stdafx.h" to the start of this file, but unfortunately, every time swig is run it will remove this fix! There is a way to fix this, but its not at all obvious (see the other answer).