如何重命名从 C 枚举类型创建的 SWIG 生成的代理 Java 类

发布于 2024-12-20 09:15:25 字数 1085 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽手叙旧 2024-12-27 09:15:25

我认为你在这里有两个问题:

  1. 你的模块与你的 (%renamed) 类型同名,所以你有两个东西想要成为Example.java。

    解决方案:更改模块名称或 %rename 中的新名称

  2. 看起来您已经为 SWIG 提供了相同 enum 的两个定义,一次接口文件和头文件中一次。

    解决方案:可能从接口文件中删除 typedef enum test_cache_t_,或者在 %include 之前使用 %ignore,或者删除 %完全包含

测试时我的最终界面文件最终看起来像这样:

%module SomeOtherName

%{
  #include "Example.h"
%}

%rename (Example) test_cache_t;

%include "Example.h"

奇怪的是,为了使其工作,我必须在 %rename 中使用 typedef 的名称,而不是 enum名称。我不太清楚为什么这似乎与 struct/class 的情况相反。

You have two problems here I think:

  1. Your module has the same name as your (%renamed) 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

  2. 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:

%module SomeOtherName

%{
  #include "Example.h"
%}

%rename (Example) test_cache_t;

%include "Example.h"

Oddly for this to work I had to use the typedef'd name in the %rename, not the enum name. I'm not quite sure why that seems to be the opposite of the case for struct/class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文