方法JNI_CreateJavaVM
的第三个参数将第三个参数作为JavaVMInitArgs
结构。
typedef struct JavaVMInitArgs {
jint version;
jint nOptions;
JavaVMOption *options;
jboolean ignoreUnrecognized;
} JavaVMInitArgs;
我该如何初始化呢?我无法这样做。
JNI_CreateJavaVM的原型:
jint JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *vm_args);
我如何初始化vm_args?
最佳答案
经过一番讨论,我们得出结论,您的编译器设置存在问题。
为了能够成功编译和链接JNI_CreateJavaVM
,您需要将jvm
库添加到链接器。
初步答案:
查看The Invocation API,以下示例可能会说明您需要执行的操作:
JavaVMInitArgs vm_args;
JavaVMOption options[4];
options[0].optionString = "-Djava.compiler=NONE"; /* disable JIT */
options[1].optionString = "-Djava.class.path=c:\myclasses"; /* user classes */
options[2].optionString = "-Djava.library.path=c:\mylibs"; /* set native library path */
options[3].optionString = "-verbose:jni"; /* print JNI-related messages */
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = TRUE;
/* Note that in the JDK, there is no longer any need to call
* JNI_GetDefaultJavaVMInitArgs.
*/
res = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args);
if (res < 0) ...