问题描述
我在java中有一个这样的包装函数:
I have a wrapped function in java like this:
dosomething(SWIGTYPE_sometypeSTRUCT STRUCTtype);
最初在 C 代码中,声明是这样的:
Originally in the C code, the declaration looks so:
dosomething(sometypeSTRUCT* structtype);
如何将 SWIGTYPE 传递给 java 函数.如果我做:SWIGTYPE_sometypeSTRUCT something = new SWIGTYPE_sometypeSTRUCT();
How can I pass the SWIGTYPE to the java function.if I do: SWIGTYPE_sometypeSTRUCT something = new SWIGTYPE_sometypeSTRUCT ();
它不起作用..只有当我设置 somthing = null 时它才会起作用.
it won't work.. It will work only if I set somthing = null.
推荐答案
问题是 SWIG 还没有看到 sometypeSTRUCT
的定义 - 据它所知dosomething
函数采用的指针是不透明类型.
The problem is that SWIG hasn't seen a definition of sometypeSTRUCT
- as far as it knows the pointer your dosomething
function takes is an opaque type.
当 SWIG 不知道细节时,它无法有意义地包装它,唯一安全的做法是让您使用此类类型在 C 中执行您可以执行的操作.
When SWIG doesn't know details it can't wrap it meaningfully and the only safe thing to do is let you do what you would be able to do in C with such a type.
要解决此问题,您可能希望使用 %include
引入结构的定义,或者可能在 SWIG 接口文件中提供定义.
To fix this you probably want to use %include
to bring in the definition of the struct, or possibly provide a definition within the SWIG interface file.
这篇关于当值为 SWIGTYPE 时如何将值传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!