JNI_CreateJavaVM() terminates with exit code 1

后端 未结 1 2084
醉梦人生
醉梦人生 2020-12-20 17:22

I\'m trying to call a Java method from C++ using JNI. To do that I\'ve installed jdk1.7.0_51, linking against jdk1.7.0_51\\lib\\jvm.lib, including

相关标签:
1条回答
  • 2020-12-20 18:03

    Using static linking

    1. remove the jvm.dll from your project directories. The dll must be loaded from it's original location, as it seems that other DLLs are involved, found by references.
    2. Set the PATH environement variable to start with the folder of a JRE jvm.dll. And don't use the "c:\folder with space in name" notation (that is surrounding the path with double quotes). Just use set path=c:\folder with space in name;%PATH%. That mistake made my previous attempts worthless.

    Using dynamic linking.

    1. remove the jvm.dll from your project directories. The dll must be loaded from it's original location, as it seems that other DLLs are involved, found by references.
    2. Drop jvm.lib from your project configuration
    3. Use LoadLibrary, with the full path for jvm.dll (escape '\' or use '/')
    4. Use GetProcAddress for "JNI_CreateJavaVM"
    5. Make sure to use a proper typedef for the function pointer (use JNICALL as calling convention)

    Patching your code with above steps makes my VS2012/Seven64/x86Debug/JDK1.6 project to output "This code is never reached" (with ret == JNI_OK)

    0 讨论(0)
提交回复
热议问题