jni本机函数重载签名 [英] jni native function overload signature

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

问题描述

在声明JNI本机函数时,我尝试使用函数重载.

I am trying to use function overload when declaring JNI native functions.

Java方法是:

public native static void methodaaa(String type, int errorCode);
public native static void methodaaa(String type, byte[] byts);

在没有过载的情况下,代码如下所示:

Without overload, the code is shown as below:

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}

这很好用.

然后我尝试添加重载:

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa(JNIEnv* env, jobject thiz, jstring type, jbyteArray buffer){}

这给了我错误:

conflicting types for Java_com_xxx_yyy_JavaCallCpp_methodaaa

然后,我进行了一些研究,似乎需要在要重载的函数的末尾添加"__",并附加参数Name mangling.

Then I did some research and it seems like I need to add a "__" to the end of the functions that I want to overload and also append the arguments Name mangling.

所以我尝试了:

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_I(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_B(JNIEnv* env, jobject thiz, jstring type, jbyteArray buffer){}

但是它仍然不起作用,错误是:

But it still not work, the error is :

No implementation found for native Lcom/xxx/yyy/JavaCallCpp;.methodaaa:(Ljava/lang/String;I)V

有人知道如何用jstring作为参数写JNICALL函数名称吗?或者我在这里做错了什么?

Is anybody know that how to write the JNICALL function name with a jstring as parameter or what I am doing wrong here?

任何建议将不胜感激,谢谢:)

Any advice will be appreciated, thanks :)

更新:

我在这里找到了链接:

http://docs.oracle .com/javase/7/docs/technotes/guides/jni/spec/design.html

,然后尝试修改我的代码:

and then tried to modify my code :

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_2I(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}

JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_2B(JNIEnv* env, jobject thiz, jstring type, jbyteArray buffer){}

但是,我仍然遇到相同的错误:

But, still I am getting the same error :

No implementation found for native Lcom/xxx/yyy/JavaCallCpp;.methodaaa:(Ljava/lang/String;I)V

推荐答案

不要试图自己弄清楚JNI方法签名.使用javah的输出.永远不会错.

Don't attempt to figure out JNI method signatures yourself. Use the output of javah. It is never wrong.

这篇关于jni本机函数重载签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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