Qt6 topics merged with General

[Solved] Linking dynamic library

  • Sorry, it is a bit unclear after reading a lot of stuff. I have several Qt libraries (dll) that I need to link dynamically. They all are located in the same directory as the .exe file, What do I put in the .pro file? This?

    LIBS+= -L /


  • Lifetime Qt Champion


    You can't link to dlls, you need the corresponding lib files

  • SGaist. Can you clarify please?
    I need to link dynamically to the libQtGuid library. Do you mean I need to copy libQtGuid.a to the folder with the exe file? Does it work for both Windows and Mac? What do I need to write in the pro file?

    LIBS+= -L .. -libQtGuid

    Is this correct?
    Many thanks!

  • I also found this in one of the threads here:
    "if library ships only dlls(rarely): manually load at runtime with LoadLibrary/GetProcAddress (or the QLibrary class equivalent) and use. Nothing is needed at compile*/link* time, .dll is needed at runtime."

    So, can I still have the .dll files stored in the exe directort and use the LoadLibrary?

    Thank you!

  • Lifetime Qt Champion

    If you setup your project correctly (pro files) the Qt libraries will be automatically linked for you, it this is not the case, you have something wrong in your project file

  • SGaist. Sorry if my message was confusing. I need to distribute the compiled project created as an exe file. So I built it and copied it to the other computer. The exe file alone cannot work without the libraries that I need to link dynamically (due to LGPL). In the folder where the exe file is, I also copied the following libraries: icudt51.dll, icuin51.dll, icuuc51.dll, libwinpthread-1.dll, Qt5Cored.dll, Qt5Guid.dll, Qt5Networked.dll, and QttWidgetsd.dll.
    How do I link dynamically to these libraries so that it works on different computers when the libraries are saved in exactly same folder with the exe file?
    Thank you for your help and patience!

  • You'll have to distribute the release versions of the Qt-dlls without the "d" before the point. You will further have to distribute the msvccpxxx.dll and msvcrxxx.dll if you use MS VS. You can check which Dlls to ship with the program "depends.exe".
    On Windows, if the program runs on the development machine it will usually also run on another machine with the correct Dlls in the same directory as the executable. On Mac/Unix/Linux, this is something completely different.

  • Lifetime Qt Champion

    For deployment information there's "the Windows deployment guide":http://qt-project.org/doc/qt-5.0/qtdoc/deployment-windows.html don't overlook the platform plugin part

  • Oh, thank you so much! I had read that guide before and I tried to do everything as it said and it never worked.

    I was missing this file: libstdc++-6.dll.

    Thanks again for your great help!

  • Sorry, I thought it was solved. Indeed, it worked on the computer with Qt installed. I sent it to a friend of mine, and it is not working on his computer. Two errors:

    1. This application failed to start because it could not find or load the Qt platform plugin "windows". Reinstall the application may fix this problem.

    2. Microsoft Visual C++ Runtime Library. This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

    "The application support team" is at a loss. I thought I have included all libraries needed. Can someone help please?

  • Sorry. qwindows.dll was in the root directory and not in platform/. Back to solved again! Special thanks to SGaist!

Log in to reply