我想从使用命名空间std的c ++头文件生成Java的包装文件,其中还包括一些库。当我尝试运行swig时,即使我的头文件来自大型代码库,并且可以正常运行,它也会给我带来语法错误,即缺少分号。

我尝试在swig所需的.i文件中包括“使用命名空间std”行,还包括.h文件中包含的类似库,但仍然存在相同的错误。

这是我的AdaptationPlanner.h文件

// some code ...
#include <string>
#include <vector>
#include <set>
using namespace std; //line 68
// more code ...


这是我的AdaptationPlanner.i文件

/* AdaptationPlanner.i */
%module AdaptationPlanner
%{
/* Includes the header in the wrapper code */
#include "AdaptationPlanner.h"
%}

/* Parse the header file to generate wrappers */
%include "AdaptationPlanner.h"



这是swig给出的错误消息:

AdaptationPlanner.h:68: Error: Syntax error - possibly a missing semicolon.

最佳答案

/* AdaptationPlanner.i */
%module AdaptationPlanner
%{
/* Includes the header in the wrapper code */
#include "AdaptationPlanner.h"
using namespace std; /* <--- */
%}

/* Parse the header file to generate wrappers */
%include "AdaptationPlanner.h"


我真的无法说出您为什么遇到这样的问题。但是,是否要尝试上述解决方案?只需在接口文件中明确提及名称空间即可。

10-07 16:20