我正在使用 SWIG 来包装 C++ 库。我收到一个错误,我认为这与我使用命名空间有关,但我不确定。不幸的是,SWIG 的文档似乎都集中在内联文档上,我不知道它从我的头文件中提取了什么。
这是我的 .i 文件:
%module cStopPow
%{
#include "../src/StopPow.h"
#include "../src/StopPow_SRIM.h"
#include "../src/StopPow_LP.h"
#include "../src/StopPow_BetheBloch.h"
%}
%include "cpointer.i"
%pointer_functions(int, intp);
%pointer_functions(float, floatp);
%include "std_vector.i"
#include <vector>
// Instantiate templates
namespace std {
%template(IntVector) vector<int>;
%template(FloatVector) vector<float>;
}
%include "std_string.i"
#include <string>
%include "../src/StopPow.h"
%include "../src/StopPow_SRIM.h"
%include "../src/StopPow_LP.h"
%include "../src/StopPow_BetheBloch.h"
这是一个裁剪的示例标题(它们的定义都非常相似):
#include ...
namespace StopPow
{
class StopPow_BetheBloch : StopPow
{ ...
其中三个类扩展了 StopPow。该库在 C++ 下编译良好,但 SWIG 给了我以下错误:
swig -java -c++ StopPow.i
../src/StopPow_BetheBloch.h:26: Warning 319: No access specifier given for base class 'StopPow' (ignored).
../src/StopPow_SRIM.h:27: Error: 'StopPow' is not a valid base class.
../src/StopPow.h:28: Error: See definition of 'StopPow'.
../src/StopPow_SRIM.h:27: Warning 401: Nothing known about base class 'StopPow'. Ignored.
../src/StopPow_LP.h:27: Error: 'StopPow' is not a valid base class.
../src/StopPow.h:28: Error: See definition of 'StopPow'.
../src/StopPow_LP.h:27: Warning 401: Nothing known about base class 'StopPow'. Ignored.
../src/StopPow_BetheBloch.h:26: Error: 'StopPow' is not a valid base class.
../src/StopPow.h:28: Error: See definition of 'StopPow'.
make: *** [StopPow] Error 6
有任何想法吗?