Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Link Qt program with DLLs



  • Hi,

    I am struggling trying to link my Qt program with some 3rd party DLLs.

    I use minGW compiler in Qt and the DLLs were compilied with MSVC 2017 (I think). The DLLs have C linkage (with extern "C") and they use __declspec(dllexport) in the functions to be exported.

    The way I try to use the DLLs is simply by adding in Qt creator an external library using the .lib and .h files path of the DLLs. Then, having the DLLs in the same directory as my executable, my program is always crashing even before it starts my mainwindow.

    As alternative, I also tried to compile my program with MSVC 2019 but I couldn't configure the kit in order to use this compiler with Qt MSVC 2017.

    Any suggestions?


  • Moderators

    @Tiago-M-Pinto said in Link Qt program with DLLs:

    I use minGW compiler in Qt and the DLLs were compilied with MSVC 2017 (I think). The DLLs have C linkage (with extern "C") and they use __declspec(dllexport) in the functions to be exported.

    MinGW and MSVC libraries are not compatible. It won't work.

    As alternative, I also tried to compile my program with MSVC 2019 but I couldn't configure the kit in order to use this compiler with Qt MSVC 2017

    I think MSVC 2017 and 2019 are binary compatible so it should work if you compile with 2019 but use libs compiled by 2017.



  • Hi @sierdzio, thank you for your reply.

    MinGW and MSVC libraries are not compatible. It won't work.

    OK, I will use MSVC.

    I think MSVC 2017 and 2019 are binary compatible so it should work if you compile with 2019 but use libs compiled by 2017.

    I just got the information that the DLLs were compiled using Visual Studio 2012 (I don't know specifically which compiler). Nevertheless, I tried a simple test consisting in calling a function in one of those DLLs using a Qt program compiled with MSVC 2019 and it still crashes. Could it be a compiler version issue?


  • Lifetime Qt Champion

    @Tiago-M-Pinto said in Link Qt program with DLLs:

    Could it be a compiler version issue?

    @sierdzio already told you that only msvc2017 and 2019 are binary compatible. So recompile your lib with 2107 or 2019 and see if it still crashes - if it is the case take a look at the backtrace to see what goes wrong.


Log in to reply