【发布时间】:2014-07-16 21:59:53
【问题描述】:
我正在尝试使用 SWIG 将一个类包装在一个用于 python 的大型 C++ 代码库中,并且在编译生成的 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 中拥有所有正确的头文件#included,因为在不使用 SWIG 时,一切都编译并运行良好。
我是否需要在其他地方提供有关我在尝试包装的头文件中使用的类的 SWIG 信息(在其他头文件中定义)?我已经阅读了 SWIG 文档的SWIG and C++ chapter,但仍然对此感到困惑。
我在 Fedora 18 上使用 SWIG 3.0.2 版和 g++ 4.7.2 版。
【问题讨论】:
-
你也应该在这里发布你的代码。这可能不足以解决您的问题。