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 Update on Monday, May 27th 2025

Cannot load dll with QLibrary using Qt5

Scheduled Pinned Locked Moved Solved Installation and Deployment
22 Posts 6 Posters 5.3k 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.
  • J JKSH
    5 Mar 2020, 14:33

    @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 5 Mar 2020, 16:54 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
    • A aha_1980
      5 Mar 2020, 14:37

      @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

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 6 Mar 2020, 02:14 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

      21/22

      5 Mar 2020, 16:54

      • Login

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