java 本机接口方法和模块名称的命名约定是什么?
What is the naming convention for java native interface method and module name?
我可以很好地学习 jni 教程。但是当我更改方法名称时,我 运行 陷入困境。我需要遵循命名约定吗?本教程使用 HelloJNI 作为模块名称和库名称。我使用了“useaaacom”。
Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:
- the prefix
Java_
- a mangled fully-qualified class name
- an underscore (
_
) separator
- a mangled method name
- for overloaded native methods, two underscores (
__
) followed by the mangled argument signature
所以如果你有以下情况:
package com.foo.bar;
class Baz {
public native void Grill(int i);
}
那么对应的C函数应该是:
JNIEXPORT void JNICALL Java_com_foo_bar_Baz_Grill(JNIEnv *env, jobject thiz, jint i);
如果Java方法名中有下划线:
public native void A_Grill(int i);
那么 C 函数将是:
JNIEXPORT void JNICALL Java_com_foo_bar_Baz_A_1Grill(JNIEnv *env, jobject thiz, jint i);
_1
转义序列匹配 A_Grill
中的 _
。
您可以在 Java 级别随意调用您的包和 class 和方法,但要遵守语言规则,但 C 级别的命名约定是完全由 javah
工具的输出定义。
您可以根据文件名规则和“System.load()/loadLibrary()”的规则随意调用共享库。
我可以很好地学习 jni 教程。但是当我更改方法名称时,我 运行 陷入困境。我需要遵循命名约定吗?本教程使用 HelloJNI 作为模块名称和库名称。我使用了“useaaacom”。
Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:
- the prefix
Java_
- a mangled fully-qualified class name
- an underscore (
_
) separator- a mangled method name
- for overloaded native methods, two underscores (
__
) followed by the mangled argument signature
所以如果你有以下情况:
package com.foo.bar;
class Baz {
public native void Grill(int i);
}
那么对应的C函数应该是:
JNIEXPORT void JNICALL Java_com_foo_bar_Baz_Grill(JNIEnv *env, jobject thiz, jint i);
如果Java方法名中有下划线:
public native void A_Grill(int i);
那么 C 函数将是:
JNIEXPORT void JNICALL Java_com_foo_bar_Baz_A_1Grill(JNIEnv *env, jobject thiz, jint i);
_1
转义序列匹配 A_Grill
中的 _
。
您可以在 Java 级别随意调用您的包和 class 和方法,但要遵守语言规则,但 C 级别的命名约定是完全由 javah
工具的输出定义。
您可以根据文件名规则和“System.load()/loadLibrary()”的规则随意调用共享库。