Error: “warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro redefinition”

橙三吉。 提交于 2019-12-08 07:16:25

问题


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

回答1:


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.




回答2:


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?


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).



来源:https://stackoverflow.com/questions/42651923/error-warning-c4005-swigtemplatedisambiguator-macro-redefinition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!