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. Using the JNI with QT - Lib/DLLs are giving a file format error

Using the JNI with QT - Lib/DLLs are giving a file format error

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 4 Posters 9.5k Views
  • 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.
  • jsulmJ Online
    jsulmJ Online
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #14

    Shouldn't this one

    LIBS += "C:/Program Files (x86)/Java/jre1.8.0_74/bin/client/jvm.dll"
    

    either be

    LIBS += -L"C:/Program Files (x86)/Java/jre1.8.0_74/bin/client" -ljvm"
    

    But it probably will not work in any case because you use MinGW and JRE most probably another (VS?) compiler. On Windows you cannot mix compilers.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • R Offline
      R Offline
      RBrNx277
      wrote on last edited by
      #15

      Aren't the -L flags only used in Linux systems? Or did I read that wrong?
      OK so the problem might be the JVM.dll was compiled with a VS compiler and I'm trying to use it with the MinGW compiler? Is there a way to check what compiler the DLL was compiled with? Could I change the Compiler QT is using to the same one?

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

        Hi,

        No they are not.

        The first problem you have is that you are trying to link against a .dll which is wrong. You need the corresponding .lib file.

        But first thing, do you need that for an Android application ?

        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
        2
        • R Offline
          R Offline
          RBrNx277
          wrote on last edited by
          #17

          Ok, I know the location of the .lib file, what should I do with it?

          No this is just a regular windows application. There's a piece of code I'd like to use which is written in Java, I will perhaps look to convert it to C++ in the future but for now I'd just like to use the exisiting Java code.

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

            Follow the example that @jsulm provided:

            LIBS += -L"C:/Path/to/Java/libs/" -ljvm"

            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
            • R Offline
              R Offline
              RBrNx277
              wrote on last edited by
              #19

              Nice one, thank you! Finally managed to get it working by only using these three lines in my .pro file

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

              and also by placing the JVM.dll where the .exe file is built by QT.

              Unfortunately my program now crashes when it attempts to create a VM for Java and says

              Error occurred during initialization of VM
              Unable to load native library: Can't find dependent libraries
              

              But I guess that's a different problem!

              1 Reply Last reply
              0
              • jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #20

                It looks like the jvm DLL depends on at least one more DLL. You can use DependencyWalker to check which dependencies you have.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply
                1
                • jsulmJ jsulm

                  It looks like the jvm DLL depends on at least one more DLL. You can use DependencyWalker to check which dependencies you have.

                  R Offline
                  R Offline
                  RBrNx277
                  wrote on last edited by
                  #21

                  @jsulm I tried using the DependencyWalker on the JVM.dll, but it gave me some very strange results. I got a LOT of missing DLLs for things like API-MS-WIN-*.dll as you can see from the images here: http://imgur.com/a/h1CvW

                  There doesn't seem to be any other DLLs missing as far as I can tell.

                  1 Reply Last reply
                  0
                  • hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on last edited by
                    #22

                    Hi maybe not a missing DLL, but perhaps too many, it could be because you have more than one version of Java installed (32-bit and 64-bit).

                    Either uninstall all the Java versions you can find on your PC and reinstall just the one you need.

                    Or you can try to change the PATH env. variable so that the first entry in it points to your correct Java version, open a CMD window:
                    PATH = "C:\Program Files (x86)\Java\jre1.8.0_74\bin\client";%PATH%

                    and try to start your app from that CMD window.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      RBrNx277
                      wrote on last edited by
                      #23

                      I just tried doing that, however my program will not run outside of QT for some reason? If I click the run button in QT the program executes fine (but then gives me the JVM error as before), but if I run the program from the command line or by double clicking on it I get an error saying:

                      The procedure entry point __cxa_throw_bad_array_new_length could not be located in the dynamic link library D:\My Documents\Qt Projects\build-PROGRAM-Desktop_Qt_5_5_1_MinGW_32bit-Release\debug\Qt5Core.dll
                      

                      I have also tried it with the release version of my program but I get the same error.

                      1 Reply Last reply
                      0
                      • hskoglundH Offline
                        hskoglundH Offline
                        hskoglund
                        wrote on last edited by
                        #24

                        Hi I think that error occurs because you copied the wrong Qt5Core.dll (from Qt Creators' bin directory) instead of the one in C:\Qt\5.5\mingw492_32\bin. Instead of copying manually, you could try windeployqt on your .exe file.

                        R 1 Reply Last reply
                        0
                        • hskoglundH hskoglund

                          Hi I think that error occurs because you copied the wrong Qt5Core.dll (from Qt Creators' bin directory) instead of the one in C:\Qt\5.5\mingw492_32\bin. Instead of copying manually, you could try windeployqt on your .exe file.

                          R Offline
                          R Offline
                          RBrNx277
                          wrote on last edited by
                          #25

                          @hskoglund I just deleted all the .dlls in my folder and copied
                          libgcc_s_dw2-1.dll
                          libwinpthread-1.dll
                          Qt5Cored.dll
                          Qt5GUId.dll
                          Qt5Widgetsd.dll

                          from the C:\Qt\5.5\mingw492_32\bin
                          into the folder where my .exe file is, unfortunately I still get the same entry point error.

                          1 Reply Last reply
                          0
                          • hskoglundH Offline
                            hskoglundH Offline
                            hskoglund
                            wrote on last edited by
                            #26

                            Hmm, that error with "__cxa_throw_bad_array_new_length" is most likely due to a mixup of your mingw and Visual Studio 2013 installation flavors of Qt.

                            You can check what flavor that Qt5Cored.dll you copied has, by downloading and running Dependency Walker, open Qt5Cored.dll and see what dlls it needs. Maybe you need to reinstall Qt :-(

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              RBrNx277
                              wrote on last edited by RBrNx277
                              #27

                              Managed to eventually get windeployqt to work, and that solved my entry point error so thank you! No idea why it wasn't accepting the DLLs that I had copied manually.

                              EDIT: I should add that windeployqt got rid of both the Entry Point error I had, along with the unable to find native library error. I have no idea how it fixed them both, perhaps it gave me a different JVM.dll.

                              1 Reply Last reply
                              0
                              • hskoglundH Offline
                                hskoglundH Offline
                                hskoglund
                                wrote on last edited by hskoglund
                                #28

                                Excellent, so maybe now you can get back to hacking/testing some Java...

                                1 Reply Last reply
                                0

                                • Login

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