简体   繁体   中英

trouble in calling java method from c++

I am trying to call java stuffs from c++ code.. I linked JDK SE 7u25's include and lib path to my visual studio 6.0 (I am just trying it in old version of MSVC).

JNIEnv* create_vm(JavaVM ** jvm) {

JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options;
options.optionString = "-Djava.class.path=C:\\Users\\myName\\Desktop\\Java Src\\TestStruct"; //Path to the java source code
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;

int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);
if(ret < 0)
    printf("\nUnable to Launch JVM\n");     
return env; }

and I get the following error...

C:\\PROGRAM FILES\\JAVA\\JDK1.7.0_25\\LIB\\jvm.lib : fatal error LNK1113: invalid machine type

What is the problem?.. I guess JNI_VERSION_1_6 might be problem..? becuase I use version SE 1.7.0_25. but I coudn't be able to find out JNI_VERSION_1_7 in jni.h file..

maybe I have to uninstall current jdk and install jdk SE 1.6 version?

Thank you for reading it :)

Maybe you are trying to link the x64 edition of lib file from 32bits of program. Please make sure you are using 32bits of JDK if you are compiling 32bits of exe.

Alternatively, you can use 'LoadLibrary' + 'GetProcAddress' to dynamically use 'jvm.dll' to call corresponding JNI functions. The same, you need to pay attention to the 32/64 edition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM