重载JNI方法 [英] Overload JNI Method

查看:98
本文介绍了重载JNI方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个参数的现有JNI方法.已经使用了一段时间,所以我不想改变它,以免释放愤怒的顾客的愤怒.

I have an existing JNI method with two parameters. Been around for a while, in use, so I don't want to just change it lest the wrath of angry customers be unleashed.

但是,我现在需要进行调整.

But, I now need to make an adjustment.

因此,我想用额外的参数制作第二个重载方法,并弃用两参数版本.该部分运行良好,jar可以构建并运行,没有任何问题.

So, I thought, make a second overloaded method with the extra parameter and deprecate the two-parameter version. That part went fine, jar builds and runs with no issues.

问题出在C ++方面...我定义了两个方法,一个方法是另一个的包装器(两个参数调用三个参数的版本),但是当我导出两个方法时,会收到:

The problem is in the C++ side... I defined two methods, one being a wrapper for the other (two parameter calls the three parameter version), but, when I went to export the two methods, I receive:

Error   1   error C2733: second C linkage of overloaded function 'Java_com_xxx' not allowed

那么,该怎么做才能保留旧方法名称并添加具有新参数的新方法?这可行吗?

So, what do I do to keep the old method name and add a new method with new parameters? Is this doable?

推荐答案

在Java文件上运行javah,声明本机方法,您将看到需要两个不同的Java_com_xxx函数. C级声明必须唯一.

Run javah on your Java file declaring the native methods and you will see that you need two different Java_com_xxx functions. The C-level declarations must be unique.

这篇关于重载JNI方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆