如何从Java端(通过JNI)访问C头文件中定义的常量?
我有一个带有头文件c_header.h的C库:
// I'll try to get these values in java
#define PBYTES 64
#define SBYTES 128
#define SGBYTES 128
Run Code Online (Sandbox Code Playgroud)
然后我有这个java代码libbind_jni.java:
package libbind;
public class libbind_jni {
static{
try {
System.load("libbind_jni.so");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static native String[] pubm(String seed);
Run Code Online (Sandbox Code Playgroud)
然后在libbind_jni.java上运行javah我生成JNI头文件jni_header.h:
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: libbind_libbind_jni
* Method: pubm
* Signature: (Ljava/lang/String;)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_lib_f_1jni_pubm
(JNIEnv *, jclass, jstring);
Run Code Online (Sandbox Code Playgroud)
然后我为JNI库jni_source.c写了一个小C代码: …