(SWIG C++到Python) 警告301: 使用class关键字,但未在C++模式中
我正在尝试为Python编译一个C++扩展。
我创建了一个接口文件foo.i,内容如下:
%module foo
%include "typemaps.i" // For pointers to primitive types
%include "std_string.i" // std::string mapping
%apply const std::string& {std::string* foo}; // data types containing std::string members
%{
#define SWIG_FILE_WITH_INIT
#include "../path/to/c++/header/files/foo_header.h"
%}
%apply double *OUTPUT { double *p, double *p2, double *p3 };
%apply double *OUTPUT { double *a1, double *a2, double *a3 };
%apply double *OUTPUT { double *a, double *b };
class FooBar
{
/*
method signatures etc ...
*/
};
当遇到class这个关键字时,就会出现一个警告。在类的声明中,有一个方法的签名里出现了C++的一个关键字(bool),这时SWIG就出错了。
我在文档中找不到任何说明,告诉我SWIG应该如何知道正在解析的文件是C++的。实际上,如果我没记错的话,文档里说SWIG可以仅通过头文件来判断一个文件是C/C++,那到底是怎么回事呢?
顺便提一下,我使用的是SWIG版本2.0.4。
1 个回答
16
如果你在用C++,那么在调用SWIG的时候需要加上 -c++
这个参数。