如何重命名从 C 枚举类型创建的 SWIG 生成的代理 Java 类
我正在尝试使用 SWIG 重命名将自动生成的代理 Java 类的名称 test_cache_t.java 更改为 Example.java。我已经尝试了下面的方法,因为它对于 C 结构运行良好,按照 这个问题,但它不适用于 C 枚举。有什么想法吗?我收到一些警告,但这些警告并不能完全引导我解决问题......
%module Example
%rename (Example) test_cache_t_;
typedef enum test_cache_t_ {
CACHE_FALSE = 0,
CACHE_TRUE = 1
} test_cache_t;
%{
#include "Example.h"
%}
%include "Example.h"
[exec] /test/include/Example.h:84: Warning 302: Identifier 'test_cache_t' redefined (ignored) (Renamed from 'test_cache_t_'),
[exec] test.i:7: Warning 302: previous definition of 'test_cache_t' (Renamed from 'test_cache_t_').
[exec] /test/include/Example.h:82: Warning 302: Identifier 'CACHE_FALSE' redefined (ignored),
[exec] test.i:5: Warning 302: previous definition of 'CACHE_FALSE'.
[exec] /test/include/Example.h:84: Warning 302: Identifier 'CACHE_TRUE' redefined (ignored),
[exec] test.i:7: Warning 302: previous definition of 'CACHE_TRUE'.
I'm trying to use the SWIG rename to change the name for the auto generated proxy Java class, test_cache_t.java to Example.java. I've tried the below, as it works fine for C structs as per this question but it's not working for C enums. Any ideas? I'm getting some warnings that don't quite lead me to the problem...
%module Example
%rename (Example) test_cache_t_;
typedef enum test_cache_t_ {
CACHE_FALSE = 0,
CACHE_TRUE = 1
} test_cache_t;
%{
#include "Example.h"
%}
%include "Example.h"
[exec] /test/include/Example.h:84: Warning 302: Identifier 'test_cache_t' redefined (ignored) (Renamed from 'test_cache_t_'),
[exec] test.i:7: Warning 302: previous definition of 'test_cache_t' (Renamed from 'test_cache_t_').
[exec] /test/include/Example.h:82: Warning 302: Identifier 'CACHE_FALSE' redefined (ignored),
[exec] test.i:5: Warning 302: previous definition of 'CACHE_FALSE'.
[exec] /test/include/Example.h:84: Warning 302: Identifier 'CACHE_TRUE' redefined (ignored),
[exec] test.i:7: Warning 302: previous definition of 'CACHE_TRUE'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你在这里有两个问题:
你的模块与你的 (
%rename
d) 类型同名,所以你有两个东西想要成为Example.java。解决方案:更改模块名称或
%rename
中的新名称看起来您已经为 SWIG 提供了相同
enum
的两个定义,一次接口文件和头文件中一次。解决方案:可能从接口文件中删除
typedef enum test_cache_t_
,或者在%include
之前使用%ignore
,或者删除%完全包含
。测试时我的最终界面文件最终看起来像这样:
奇怪的是,为了使其工作,我必须在
%rename
中使用typedef
的名称,而不是enum名称。我不太清楚为什么这似乎与
struct
/class
的情况相反。You have two problems here I think:
Your module has the same name as your (
%rename
d) type, so you have two things wanting to be Example.java.Solution: change the name of either the module or the new name from
%rename
It looks like you've provided SWIG two definitions of the same
enum
, once in the interface file and once in the header file.Solution: probably remove
typedef enum test_cache_t_
from the interface file, alternatively use%ignore
before the%include
, or drop the%include
altogether.My final interface file when testing ended up looking like:
Oddly for this to work I had to use the
typedef
'd name in the%rename
, not theenum
name. I'm not quite sure why that seems to be the opposite of the case forstruct
/class
.