SWIG 接口文件结构导致重复的 Java 函数
我有以下 SWIG 接口文件结构,我认为该结构无效。 int func(ussigned char key[20]) 位于 headerThree.h 中。当我离开 %include "HeaderThree.h" 时,我得到一个重复的 int func(SWIGTYPE_p_unsigned_char key); 。如果我删除 %include "HeaderThree.h",其他函数不会显示在生成的 Example.java 文件中。只有 int func(short[] key) 会显示。我想将 SWIG .i 文件配置为不具有 func(SWIGTYPE_p_unsigned_char key) 函数,但将其余函数包含在 HeaderThree.h 中。有什么想法吗?
%module Example
%{
#include "HeaderOne.h" //has constants and type definitions
#include "HeaderTwo.h" // has an #include "HeaderOne.h" and its own C apis
#include "HeaderThree.h" // has an #include "HeaderOne.h" and its own C apis
%}
%include "arrays_java.i"
int func(unsigned char key[20]);
%include "HeaderOne.h" //has constants and type definitions
%include "HeaderTwo.h" // has an #include "HeaderOne.h" and its own C apis
%include "HeaderThree.h" // has an #include "HeaderOne.h" and its own C apis
I have the below SWIG Interface file structure that I feel is invalid. The int func(usigned char key[20]) resides in headerThree.h. When I leave in the %include "HeaderThree.h" I get a duplicate int func(SWIGTYPE_p_unsigned_char key);. If I remove the %include "HeaderThree.h", the other functions do not show up in the generated Example.java file..only the int func(short[] key) does. I would like to configure the SWIG .i file to not have the
func(SWIGTYPE_p_unsigned_char key) function but to have the rest of the functions included in HeaderThree.h. Any ideas?
%module Example
%{
#include "HeaderOne.h" //has constants and type definitions
#include "HeaderTwo.h" // has an #include "HeaderOne.h" and its own C apis
#include "HeaderThree.h" // has an #include "HeaderOne.h" and its own C apis
%}
%include "arrays_java.i"
int func(unsigned char key[20]);
%include "HeaderOne.h" //has constants and type definitions
%include "HeaderTwo.h" // has an #include "HeaderOne.h" and its own C apis
%include "HeaderThree.h" // has an #include "HeaderOne.h" and its own C apis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题是,当您说
%include
时,就好像您直接在该点粘贴了文件的内容(即要求 SWIG 将其全部包装起来)。这意味着 SWIG 已经看到了func
的两个版本,即您明确告知的版本和您%include
标头中实际存在的版本。有几种方法可以解决这个问题,尽管额外的过载并没有真正造成任何伤害,但它只是吵闹和混乱。
使用
#ifndef SWIG
在 SWIG 的头文件中隐藏func
的声明。然后你的头文件将变成:<前><代码>#ifndef SWIG
int func(无符号字符 *key);
#endif
当您
%include
时,头文件 SWIG 将看不到此版本的func
- 但这不是问题,因为您明确告诉它另一个版本(即与 SWIG 兼容)使用
%ignore
指示 SWIG 专门忽略此版本的func
。 SWIG 模块文件将变为:您还可以更改头文件中
func
的实际声明和定义以及它在代码中实际实现的位置,以使用unsigned char[20 ]
而不是unsigned char*
。The problem here is that when you say
%include
it is as though you pasted the contents of the file directly at that point (i.e. asked SWIG to wrap it all). This means SWIG has seen both versions offunc
, the one you explicitly told it about and the one that actually exists in the header you%include
d.There's a couple of ways you can fix this, although having the extra overload kicking around doesn't really do any harm, it's just noisy and messy.
Hide the declaration of
func
in the header file from SWIG using#ifndef SWIG
. Your header file would then become:When you
%include
that header file SWIG won't see this version offunc
- that's not a problem though because you explicitly told it about another version (which is compatible for the purposes of SWIG)Use
%ignore
to instruct SWIG to ignore this version offunc
specifically. The SWIG module file then becomes:You could also change the actual declaration and definition of
func
in the header file and the place it's actually implemented in your code to useunsigned char[20]
instead ofunsigned char*
.