Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: undefined reference to `_imp__JNI_CreateJavaVM@12'

error: undefined reference to `_imp__JNI_CreateJavaVM@12'

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Is your Java library compiled with the same compiler ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        WhatIf
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • W Offline
            W Offline
            WhatIf
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved