[Solved] Deploying third-party shared libraries from QtCreator on Windows

  • I am developing an application that has dependencies on several third-party shared libraries on windows.

    The application will also be deployed on Linux, but the typical library paths (/usr/lib, /usr/local/lib) will occomodate Linux builds very easily.

    My question is, what is the proper way to copy the third-party shared libraries into the build directory within QtCreator. I have the DESTDIR variable set (this is not a shadow build, as the path for building is explicitly defined in the .pro file), so the executables are built in an explicitly defined location. Additionally, I control where the moc and .o files are placed. I would like the final step for a build to copy the shared libraries from my project's ./thirdparty folder into the build directory, so that when I run the executable from QtCreator, it doesn't crash with a failed shared library load.

    The purpose for bundling shared object files from QtCreator is to allow other developers (with very little experience deploying shared library applications) to collaborate on this project without having to endure a lot of pain in file management. I would like QtCreator to do the work for them. This of course minimizes the chances of them screwing it up and pestering me to do these things for them.

    I have tried using the DISTFILES variable, the INSTALLS variable, as well as some other kookier things to make this happen. What is the preferred method?

  • I usuaually just adjust the PATH variable to point to my 3rdparty folder. Otherwise you can do sth. like this:
    QMAKE_POST_LINK += copy /Y $$PWD\thirdparty\* $$replace(DESTDIR,"/","\") $$escape_expand(\n\t)

  • Moved to Installation & Deployment forum.

  • Yes, I use same:
    @QMAKE_POST_LINK = cp -f $$IN_PWD/lib/mylib.1.0.0.dylib $$DESTDIR@

  • Thank you for the help. I used QMAKE_PRE_LINK instead of the post-link option. Since I'm bundling the .dll's anyway, it makes sense to link against them in their new homes. Anyhow, this is how my .pro ended up looking (in part)

    win32 {
    message( "linking libraries for windows" )

    LIBS += -L $$DESTDIR
    !exists( $$DESTDIR/glew32.dll ) {
        COPY_CMD += copy $$ROOT/thirdparty/glew/lib/glew32.dll $$DESTDIR &
    LIBS += -lglew32
    !exists( $$DESTDIR/jpeg62.dll ) {
        COPY_CMD += copy $$ROOT/thirdparty/jpeg/lib/jpeg62.dll $$DESTDIR &
    LIBS += -ljpeg62
    !exists( $$DESTDIR/libopencv_imgproc230.dll ) {
        COPY_CMD += copy $$ROOT/thirdparty/opencv/lib/libopencv_imgproc230.dll $$DESTDIR &
    LIBS += -lopencv_imgproc230
    !exists( $$DESTDIR/libopencv_core230.dll ) {
        COPY_CMD += copy $$ROOT/thirdparty/opencv/lib/libopencv_core230.dll $$DESTDIR &
    LIBS += -lopencv_core230
    COPY_CMD  = $$replace( COPY_CMD, "/", "\\" ) $$escape_expand( \\n\\t )


    This works very well for me. Thanks again!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.