使用 SWIG %apply 重命名 C 结构体属性
我的 SWIG 接口文件和我的 Sample.h 头文件中有以下结构。我假设此结构中的 sockaddr、ios_boolean 和 unsigned char 定义是我得到以下生成的类的原因。如果我知道 ios_boolean 和 unsigned char 映射到 Java 端的类型,有没有办法使用 %apply 来摆脱生成的指针类?我尝试过 %apply int {ios_boolean};但后来我得到了 SWIGTYPE_p_boolean.java。有什么想法吗?
%rename (Sample) sample_details_t_;
typedef struct sample_details_t_ {
ios_boolean is_allowed;
unsigned char mac[11];
} sample_t;
generates:
SWIGTYPE_p_unsigned_char.java
SWIGTYPE_p_ios_boolean.java
例外:
[exec] ewapi_wrap.c:982: error: `true' undeclared (first use in this function)
[exec] ewapi_wrap.c:982: error: (Each undeclared identifier is reported only once
[exec] ewapi_wrap.c:982: error: for each function it appears in.)
[exec] ewapi_wrap.c:982: error: `false' undeclared (first use in this function
I have the below structure in my SWIG interface file and thusly my sample.h header file. I'm assuming the sockaddr, ios_boolean and unsigned char definitions from this structure are the reason why I get the below generated classes. If I know the type on that ios_boolean and unsigned char map to on the Java side is there a way to use an %apply to get rid of the generated pointer classes? I tried %apply int {ios_boolean}; but then I get a SWIGTYPE_p_boolean.java. Any ideas?
%rename (Sample) sample_details_t_;
typedef struct sample_details_t_ {
ios_boolean is_allowed;
unsigned char mac[11];
} sample_t;
generates:
SWIGTYPE_p_unsigned_char.java
SWIGTYPE_p_ios_boolean.java
Exception:
[exec] ewapi_wrap.c:982: error: `true' undeclared (first use in this function)
[exec] ewapi_wrap.c:982: error: (Each undeclared identifier is reported only once
[exec] ewapi_wrap.c:982: error: for each function it appears in.)
[exec] ewapi_wrap.c:982: error: `false' undeclared (first use in this function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想做类似的事情:
这将
mac
包装为short[]
(对数组大小进行限制)并将is_allowed
包装为Java 端的 boolean
并生成以下文件:确保删除旧版本 SWIG 界面中存在的所有旧
SWIGTYPE_*.java
文件,它们不会自动删除,并且可能无法删除如果您执行类似javac *.java
的操作,则进行编译。You probably want to do something like:
This wraps
mac
asshort[]
(with constraints on the array size) andis_allowed
asboolean
on the Java side and results in these files:Make sure you delete any old
SWIGTYPE_*.java
files that are lying around from older versions of your SWIG interface, they won't get deleted automatically and might fail to compile if you do something likejavac *.java
.