[英]SWIG: using imported external type
I am trying to wrap some libraries written in C++ to interface with JAVA using SWIG. 我正在尝试包装一些用C ++编写的库,以便使用SWIG与JAVA接口。
I have one C++ struct in one library used in one C++ function of another library as an argument. 我在一个库中有一个C ++结构,该库在另一个库的一个C ++函数中用作参数。
common.h COMMON.H
namespace rina {
namespace cdap_rib {
typedef struct{
int size_;
void* message_;
} ser_obj_t;
}
}
This library is wrapped producing a class called eu.irati.librina.ser_obj_t
in JAVA. 该库经过包装,在JAVA中产生了一个名为
eu.irati.librina.ser_obj_t
的类。 That's fine. 没关系。 Then I have
那我有
utilities.h utilities.h
class IPCPConfigEncoder {
public:
void encode (rina::cdap_rib::ser_obj_t& ser_obj);
}
which is wraped with SWIG producing 用SWIG生产包装
public void encode(SWIGTYPE_p_rina__cdap_rib__ser_obj_t ser_obj) {
...
}
in a JAVA class. 在JAVA类中。 Looking around in I found ( SWIG Importing generated class from a different module and package into the current class ) and I added to .i
环顾四周,我发现了( SWIG将生成的类从其他模块导入并封装到当前类中 ),然后将其添加到.i中。
%typemap(javaimports) SWIGTYPE
%{
import eu.irati.librina.ser_obj_t;
%}
which produced 产生了
import eu.irati.librina.ser_obj_t;
public void encode(SWIGTYPE_p_rina__cdap_rib__ser_obj_t ser_obj) {
...
}
Then, I have a couple of questions 然后,我有几个问题
The import
is added to all the java classes... how can I enclose it only to the desired class? import
被添加到所有java类中...如何将其仅包含在所需的类中?
How can I tell SWIG to change SWIGTYPE_p_rina__cdap_rib__ser_obj_t
for eu.irati.librina.ser_obj_t
. 我如何告诉SWIG更改
SWIGTYPE_p_rina__cdap_rib__ser_obj_t
的eu.irati.librina.ser_obj_t
。
Note: Since common.h
and utilities.h
are in different libraries I can not put them together in the same swig module. 注:由于
common.h
和utilities.h
在不同的图书馆,我不能把它们放在一起一样痛饮模块中。
As @Felxo pointed in the coments, the only solution is to tell swig to understand also the other libraries interface wraping (so headers and how are they wrapped). 正如@Felxo在评论中指出的那样,唯一的解决方案是告诉swig还了解其他库的接口包装(因此,标头及其包装方式)。
What I did: 我做了什么:
common.i
into utilities wrapping folder. common.i
复制到实用程序包装文件夹中。 I added into utilities.i
我添加到
utilities.i
/* this is the "copied" common.i */ %import "common.i" %pragma(java) jniclassimports=%{ import eu.irati.librina.ser_obj_t; %}
to add the import of the proxy class (you should change thais to point to your proxy class from a java path) 添加代理类的导入(您应该更改Thais使其从Java路径指向您的代理类)
Remove from the copied common.i
the unecessary instructions like %template
, remember that, at this point, you are only "importing" the common.h, not wrapping it (you already wraped it before). 从复制的
common.i
删除不必要的说明,例如%template
,请记住,此时,您只是“导入” common.h,而不是包装它(之前已经包装了它)。 Actually, the common.i
should only include: 实际上,
common.i
应该仅包括:
%{ #include "common.h" }%
but no 但不是
%include "common.h"
common.h
as well as where is the utilities.h
using the -I
option common.h
以及哪里是utilities.h
使用-I
选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.