Error: "warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro redefinition"

Error: "warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro redefinition"

我正在尝试编译一个 SWIG 项目,但它一直出现这样的错误:

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

错误如下:

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

编译器

在Visual Studio中,右击swig-generated.cpp包装文件,select“不使用预编译Headers”。

在我的例子中,swig auto-generated 的包装文件是 swig_wrap.cpp

您可以为整个项目保留预编译 headers。

有关详细信息,请参阅 nabble.com 和 Fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?


附录 A:SWIG 可以修复以避免这种情况!

解决此问题的另一种方法是手动将行“stdafx.h”添加到此文件的开头,但不幸的是,每次 swig 为 运行 时都会删除此行使固定!有一种方法可以解决此问题,但它一点也不明显(请参阅其他答案)。

将以下内容添加到您的 .i 文件中:

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

此部分将代码注入到文件顶部生成的包装器中,您无需禁用 pre-compiled headers.