繁体   English   中英

SWIG生成的C ++包装器会导致许多编译错误

[英]SWIG-generated C++ wrapper causes many compilation errors

我正在尝试使用SWIG在大型C ++代码库中为python包装一个类,并且在编译生成的C ++包装器时遇到一些问题。

我创建了一个基本的接口文件PCSearchResult.i:

%module PCSearchResult
%{
 #include "PCSearchResult.h"
%}
%include "PCSearchResult.h"

我使用以下命令生成了PCSearchResult_wrap.cxx:

swig -c++ -python PCSearchResult.i 

并尝试使用以下命令进行编译:

g++ -c -fpic -I. -I$(OTHERINCS) -I/usr/include/python2.7 PCSearchResult_wrap.cxx

这导致大量错误。 这是前15行:

PCSearchResult_wrap.cxx: In function 'PyObject* _wrap_new_PCSearchResult__SWIG_1(PyObject*, PyObject*)':
PCSearchResult_wrap.cxx:3226:3: error: 'Point3d' was not declared in this scope
PCSearchResult_wrap.cxx:3226:3: note: suggested alternative:
In file included from PointCloud.h:28:0,
                 from PCSearchResult.h:29,
                 from PCSearchResult_wrap.cxx:3044:
Point3d.h:43:7: note:   'Isis::Point3d' 
PCSearchResult_wrap.cxx:3226:12: error: 'arg1' was not declared in this scope
PCSearchResult_wrap.cxx:3230:19: error: 'PointCloud' was not declared in this scope
PCSearchResult_wrap.cxx:3230:19: note: suggested alternative:
In file included from PCSearchResult.h:29:0,
                 from PCSearchResult_wrap.cxx:3044:
PointCloud.h:80:7: note:   'Isis::PointCloud'
PCSearchResult_wrap.cxx:3230:30: error: template argument 1 is invalid
PCSearchResult_wrap.cxx:3230:38: error: invalid type in declaration before '=' token

所有“未在此范围内声明”的错误使我认为我一定无法在正确的位置包含某些内容。 我知道我在PCSearchResult.h中包含了所有正确的头文件,因为在不使用SWIG时,所有文件都可以编译并运行良好。

我还需要在其他地方提供SWIG信息,以获取我要包装的头文件(在其他头文件中定义)中使用的类的信息吗? 我已经阅读了SWIG文档的SWIG和C ++章节 ,对此仍然感到困惑。

我在Fedora 18上使用的是SWIG版本3.0.2和g ++版本4.7.2。

看起来Point3d在名称空间中。 在您自己的源文件中,您可能使用完整的decl,或者在源文件中使用using名称空间decl。 因此,尝试添加一个using namespace Isis; 在.i文件中:

%module PCSearchResult
%{
#include "PCSearchResult.h"
using namespace Isis;
%}
%include "PCSearchResult.h"

这会将其插入wrap.cxx文件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM