Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Cannot load dll with QLibrary using Qt5
Forum Updated to NodeBB v4.3 + New Features

Cannot load dll with QLibrary using Qt5

Scheduled Pinned Locked Moved Solved Installation and Deployment
22 Posts 6 Posters 5.6k Views 4 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.
  • aha_1980A aha_1980

    @Tiago-M-Pinto

    Please collapse all the EXT-MS-* and API-MS-* entries. Then you'll see the real problematic ones.

    How can I know which dependecies are these? Do I have to provide the path for them? How?

    With Dependency Walker, e.g. Either copy the deps to the program or provides them with the PATH variable.

    Btw., for deployment please use https://doc.qt.io/qt-5/windows-deployment.html

    Regards

    T Offline
    T Offline
    Tiago M.Pinto
    wrote on last edited by
    #10

    @aha_1980

    Please collapse all the EXT-MS-* and API-MS-* entries. Then you'll see the real problematic ones.

    After searching for errors different than EXT-MS-* and API-MS-*, I found that hvsifiletrust.dll and IEShims.dll were missing. I do not know if they could be ignored so I downloaded them from the web and put them in my program directory but it still does not work.

    1 Reply Last reply
    0
    • artwawA artwaw

      @Tiago-M-Pinto The only thing that comes to my mind is that the lib version (or type, confused 32/64bit) is mismatched. Maybe some more experienced member of the community will be able to provide more help?

      T Offline
      T Offline
      Tiago M.Pinto
      wrote on last edited by
      #11

      @artwaw I just found out that my 3rd party DLLs were compiled using MS Visual Studio (probably MSVC). Could this be the problem since I am compiling my program with MinGW?

      artwawA JKSHJ 2 Replies Last reply
      0
      • T Tiago M.Pinto

        @artwaw I just found out that my 3rd party DLLs were compiled using MS Visual Studio (probably MSVC). Could this be the problem since I am compiling my program with MinGW?

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #12

        @Tiago-M-Pinto Yes. They need to be recompiled with minGW or you should compile your program using MSVS.

        For more information please re-read.

        Kind Regards,
        Artur

        T 1 Reply Last reply
        1
        • artwawA artwaw

          @Tiago-M-Pinto Yes. They need to be recompiled with minGW or you should compile your program using MSVS.

          T Offline
          T Offline
          Tiago M.Pinto
          wrote on last edited by Tiago M.Pinto
          #13

          @artwaw OK, thank you. I will try to do that. However, I was using the same DLLs before while compiling my program with MinGW and everything worked just fine. How could that be?

          artwawA 1 Reply Last reply
          0
          • T Tiago M.Pinto

            @artwaw OK, thank you. I will try to do that. However, I was using the same DLLs before while compiling my program with MinGW and everything worked just fine. How could that be?

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #14

            @Tiago-M-Pinto Can't say. There must be differences in how the library exposes the data but I have very little knowledge on how exactly they differ - I tried MSVC once and ran away screaming, minGW is so much easier on Windows. Me myself I always use minGW for everything on Windows and it just... works.

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • T Tiago M.Pinto

              @artwaw I just found out that my 3rd party DLLs were compiled using MS Visual Studio (probably MSVC). Could this be the problem since I am compiling my program with MinGW?

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #15

              @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

              @artwaw I just found out that my 3rd party DLLs were compiled using MS Visual Studio (probably MSVC). Could this be the problem since I am compiling my program with MinGW?

              You didn't say if the 3rd-party code is written in C or C++.

              If they are C++ DLLs, then they must use compatible compilers because of Name Mangling.

              C DLLs don't have name mangling so they can be mixed.

              I put the dlls in the build directory and the corresponding errorString returns: "Cannot load library xxxxxx: The specified module could not be found."

              You said you "put the DLLs in the build directory"...

              1. What is the absolute path of that dirrectory?
              2. What path did you give to QLibrary?
              3. What does QDir::currentPath() give you right before you initialize your QLibrary?

              Finally, what are the DLLs that you're loading? Do you really need QLibrary? Could you link the DLLs directly to your executable instead?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              T 1 Reply Last reply
              3
              • JKSHJ JKSH

                @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

                @artwaw I just found out that my 3rd party DLLs were compiled using MS Visual Studio (probably MSVC). Could this be the problem since I am compiling my program with MinGW?

                You didn't say if the 3rd-party code is written in C or C++.

                If they are C++ DLLs, then they must use compatible compilers because of Name Mangling.

                C DLLs don't have name mangling so they can be mixed.

                I put the dlls in the build directory and the corresponding errorString returns: "Cannot load library xxxxxx: The specified module could not be found."

                You said you "put the DLLs in the build directory"...

                1. What is the absolute path of that dirrectory?
                2. What path did you give to QLibrary?
                3. What does QDir::currentPath() give you right before you initialize your QLibrary?

                Finally, what are the DLLs that you're loading? Do you really need QLibrary? Could you link the DLLs directly to your executable instead?

                T Offline
                T Offline
                Tiago M.Pinto
                wrote on last edited by Tiago M.Pinto
                #16

                Hello @JKSH, thank you for your reply.

                You didn't say if the 3rd-party code is written in C or C++.

                The 3rd-party code is written in C and its header file is written in this way:

                #ifdef __cplusplus
                extern "C" {
                #endif
                
                #ifdef DLLEXP_UTIL
                __declspec(dllexport)
                #endif
                void myFunc(void);
                
                #ifdef __cplusplus
                }
                #endif
                

                I presume the keyword __declspec(dllexport) is from MSVC. If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?

                Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?

                1. What is the absolute path of that dirrectory?

                C:\Users\Tiago\Google Drive\Projects\build-project-Desktop_Qt_5_14_1_MinGW_64_bit-Release

                1. What path did you give to QLibrary?

                To load the DLLs I only gave their name in the code becasue (as I already posted here) the directory above is included in the search paths.

                1. What does QDir::currentPath() give you right before you initialize your QLibrary?

                It gives me the directory above.

                Finally, what are the DLLs that you're loading? Do you really need QLibrary? Could you link the DLLs directly to your executable instead?

                The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?

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

                  Hi,

                  If you want to use the export/import part, it's a bit more complicated than just __declspec. Take a look at the Creating Shared Libraries chapter in Qt's documentation.

                  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
                  • T Tiago M.Pinto

                    Hello @JKSH, thank you for your reply.

                    You didn't say if the 3rd-party code is written in C or C++.

                    The 3rd-party code is written in C and its header file is written in this way:

                    #ifdef __cplusplus
                    extern "C" {
                    #endif
                    
                    #ifdef DLLEXP_UTIL
                    __declspec(dllexport)
                    #endif
                    void myFunc(void);
                    
                    #ifdef __cplusplus
                    }
                    #endif
                    

                    I presume the keyword __declspec(dllexport) is from MSVC. If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?

                    Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?

                    1. What is the absolute path of that dirrectory?

                    C:\Users\Tiago\Google Drive\Projects\build-project-Desktop_Qt_5_14_1_MinGW_64_bit-Release

                    1. What path did you give to QLibrary?

                    To load the DLLs I only gave their name in the code becasue (as I already posted here) the directory above is included in the search paths.

                    1. What does QDir::currentPath() give you right before you initialize your QLibrary?

                    It gives me the directory above.

                    Finally, what are the DLLs that you're loading? Do you really need QLibrary? Could you link the DLLs directly to your executable instead?

                    The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by JKSH
                    #18

                    @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

                    If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?

                    Usually, extern "C" means the DLL can be loaded with any executable compiled with any C/C++ compiler.

                    Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?

                    The best way to find out is to try it.

                    The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?

                    It doesn't sound like you need a library to use the DLL. Just add the header and library to your *.pro file, and then #include the header in your .cpp code and call the function directly!

                    Example: If you have these files...

                    • C:\my3rdpartystuff\include\foo.h
                    • C:\my3rdpartystuff\bin\foo.dll

                    ...then add this to your *.pro file:

                    INCLUDEPATH += "C:/my3rdpartystuff/include"
                    LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
                    

                    [EDIT: Trailing slashes removed from the 2 lines above]

                    If there are any problems, the compiler and linker will tell you.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    aha_1980A T 3 Replies Last reply
                    2
                    • JKSHJ JKSH

                      @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

                      If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?

                      Usually, extern "C" means the DLL can be loaded with any executable compiled with any C/C++ compiler.

                      Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?

                      The best way to find out is to try it.

                      The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?

                      It doesn't sound like you need a library to use the DLL. Just add the header and library to your *.pro file, and then #include the header in your .cpp code and call the function directly!

                      Example: If you have these files...

                      • C:\my3rdpartystuff\include\foo.h
                      • C:\my3rdpartystuff\bin\foo.dll

                      ...then add this to your *.pro file:

                      INCLUDEPATH += "C:/my3rdpartystuff/include"
                      LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
                      

                      [EDIT: Trailing slashes removed from the 2 lines above]

                      If there are any problems, the compiler and linker will tell you.

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #19

                      @JKSH, that is a very good post!

                      Just one addition:

                      INCLUDEPATH += "C:/my3rdpartystuff/include/"
                      LIBS += -L"C:/my3rdpartystuff/bin/" -lfoo

                      It might be useful to omit the trailing slashes for the directories.

                      INCLUDEPATH += "C:/my3rdpartystuff/include"
                      LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
                      

                      On Windows these are converted to backslashes and can cause problems on line ends, for example.

                      Regards

                      Qt has to stay free or it will die.

                      JKSHJ 1 Reply Last reply
                      2
                      • JKSHJ JKSH

                        @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

                        If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?

                        Usually, extern "C" means the DLL can be loaded with any executable compiled with any C/C++ compiler.

                        Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?

                        The best way to find out is to try it.

                        The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?

                        It doesn't sound like you need a library to use the DLL. Just add the header and library to your *.pro file, and then #include the header in your .cpp code and call the function directly!

                        Example: If you have these files...

                        • C:\my3rdpartystuff\include\foo.h
                        • C:\my3rdpartystuff\bin\foo.dll

                        ...then add this to your *.pro file:

                        INCLUDEPATH += "C:/my3rdpartystuff/include"
                        LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
                        

                        [EDIT: Trailing slashes removed from the 2 lines above]

                        If there are any problems, the compiler and linker will tell you.

                        T Offline
                        T Offline
                        Tiago M.Pinto
                        wrote on last edited by
                        #20

                        @JKSH, thank you again.

                        The best way to find out is to try it.

                        I compiled a simple DLL using minGW and it finally worked using QLibrary.

                        It doesn't sound like you need a library to use the DLL. Just add the header and library to your *.pro file, and then #include the header in your .cpp code and call the function directly!

                        You are right, I will do that. I didn't think about it but it... that way I can avoid resolves using QLibrary.

                        1 Reply Last reply
                        0
                        • JKSHJ JKSH

                          @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

                          If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?

                          Usually, extern "C" means the DLL can be loaded with any executable compiled with any C/C++ compiler.

                          Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?

                          The best way to find out is to try it.

                          The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?

                          It doesn't sound like you need a library to use the DLL. Just add the header and library to your *.pro file, and then #include the header in your .cpp code and call the function directly!

                          Example: If you have these files...

                          • C:\my3rdpartystuff\include\foo.h
                          • C:\my3rdpartystuff\bin\foo.dll

                          ...then add this to your *.pro file:

                          INCLUDEPATH += "C:/my3rdpartystuff/include"
                          LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
                          

                          [EDIT: Trailing slashes removed from the 2 lines above]

                          If there are any problems, the compiler and linker will tell you.

                          T Offline
                          T Offline
                          Tiago M.Pinto
                          wrote on last edited by
                          #21

                          @JKSH just one more thing:

                          I couldn't add my DLL as you said but all worked out by adding the library using Qt Creator interface (in "Add Library..." -> "External Library") which asks for the .a file and the include path.

                          1 Reply Last reply
                          1
                          • aha_1980A aha_1980

                            @JKSH, that is a very good post!

                            Just one addition:

                            INCLUDEPATH += "C:/my3rdpartystuff/include/"
                            LIBS += -L"C:/my3rdpartystuff/bin/" -lfoo

                            It might be useful to omit the trailing slashes for the directories.

                            INCLUDEPATH += "C:/my3rdpartystuff/include"
                            LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
                            

                            On Windows these are converted to backslashes and can cause problems on line ends, for example.

                            Regards

                            JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by
                            #22

                            @Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:

                            I compiled a simple DLL using minGW and it finally worked using QLibrary.

                            ...

                            I couldn't add my DLL as you said but all worked out by adding the library using Qt Creator interface (in "Add Library..." -> "External Library") which asks for the .a file and the include path.

                            Sounds like you got it to work in 2 different ways. Congrats, and happy coding!

                            @aha_1980 said in Cannot load dll with QLibrary using Qt5:

                            It might be useful to omit the trailing slashes for the directories.

                            ...

                            On Windows these are converted to backslashes and can cause problems on line ends, for example.

                            Edited, thanks!

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            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