error: undefined reference to `_imp__JNI_CreateJavaVM@12'

  • Hi,

    I'm trying to get my first c++/java to work but I have an error, which is produced by the following line of code

    jint rc = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

    error: undefined reference to `_imp__JNI_CreateJavaVM@12'

    Some online posts suggested to add

    LIBS += -L"C:/Program Files/Java/jdk1.8.0_131/lib/" -ljvm

    to the .pro but it doesn't make a difference.

    I also tried

    LIBS += -L"C:/Program Files/Java/jdk1.8.0_131/lib/jvm.lib" -ljvm

    I don't receive undefined reference to `_imp__JNI_CreateJavaVM@12' but I get a different error

    error: cannot find -ljvm

    How can I get it to work?

  • Lifetime Qt Champion


    What version of Qt are you using ? With which compiler ?

    Is your Java library compiled with the same compiler ?

  • Qt Creator 4.3.1
    Based on Qt 5.9.1 (MSVC 2015, 32 bit)

    MinGW 5.3.0 32bit for C++

    Is your Java library compiled with the same compiler?

    I'm not sure if I understood you correctly but I install java using an executable on Windows.

    The following is all I added to my .pro

    INCLUDEPATH += "C:/Program Files/Java/jdk1.8.0_131/include/"
    INCLUDEPATH += "C:/Program Files/Java/jdk1.8.0_131/include/win32"
    LIBS += -L"C:/Program Files/Java/jdk1.8.0_131/lib/" -ljvm

  • Lifetime Qt Champion

    Java is likely built with Visual Studio. You can't mix and match libraries built with different compilers on Windows especially VS and MinGW, but also prior to VS2017, there was no compatibility between versions of VS however VS2017 is compatible with VS2015.

  • What do I need to do to get jni to work in Qt Creator 4.3.1?

  • Lifetime Qt Champion

    This has nothing to do with Qt Creator.

    Like I already wrote, you have to ensure that you are using the same compiler everywhere so you should check which version of Visual Studio was used to build your java library and use that one to build your application which implies to download Qt for that compiler also.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.