方法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?
答案 0 :(得分:5)
经过一番讨论,我们得出结论,你的编译器设置有问题。
为了能够成功编译和链接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) ...