Qt World Summit: Register Today!

[Solved] Linking statically against some libs

  • Hello,

    sorry for this beginner question but I'm somehow stuck...
    I'm playing around with Qt and created a small application which perfectly compiles and runs on Linux. It uses libical and boost. Now I would like to build it on Windows. Installing the libs went smoothly (using MinGW). But now I think QtCreator (or qmake, that is) tries to link dynamically. How can I link to these libs (not Qt!) statically?

    What makes me wonder is that QtCreator thinks that the (static) libs end with .lib, but their suffix is .a. So, I can't add them via the GUI dialog, but did it manually, for example:
    @win32: INCLUDEPATH += $$quote(C:/mylibs/mingw/include)
    win32: LIBS += -L$$quote(C:/mylibs/mingw/lib) -llibical@

    Somewhere I read that CONFIG += static will do the trick, but it doesn't change anything.

    So, maybe you can help me with this.

    Thanks a lot

  • welcome to devnet

    The Qt precompiled versions are always for dynamic linking. You would need to compile Qt by yourself for static linking.

    However, beware of the "license issues":http://qt.nokia.com/products/licensing as well.

  • Thanks koahnig. I'm aware of the licensing model. So it isn't possible to link some libs (Qt) dynamically and some others statically? I wasn't aware of this linker restriction (haven't done so much with libs).

    But then it would be nice if the build process would copy the dynamic libs into the build-dir so that the .exe can find them (on windows, that is), right?

  • Hello,
    Linking some libs statically and Qt dynamically is totally possible. The .a file should be ok as long as you compiled it for Windows or you downloaded windows version. I think Qt Creator has nothing to do with your problem but it's more gcc (or more precisely the linker) which handles your libraries while building. CONFIG += static is for compiling your lib statically not the app.
    What messages have you got? Missing references while linking, missing dll when running?

  • My remark on dynamic distribution was about the Qt libs only. As already asked by unai_i what are your error messages?

  • I only got the message, that the linker couldn't find the lib, e.g.:
    @c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -llibboost_date_time-mgw47-mt-1_50@

    But the .a files are available. If I compile boost also for dynamic linking (.dll.a, if I understand this correctly), the linker finds the lib but links it dynamically.

    Maybe I just don't know how to tell qmake that I want to link dynamically?

  • May be not much of help but there is a video tutorial "here":http://www.voidrealms.com/viewtutorial.aspx?id=245 that you can check .

  • Sam, yes, that was it. Thanks a lot! What I had to do is:
    @win32: LIBS += "C:/mylibs/mingw/lib/llibboost_date_time-mgw47-mt-1_50.a"@

  • You are welcome,

    Glad to know that its working :) Kindly Edit the title and add [Solved]

  • Ok, title is edited. The only problem now is that my current MinGW/GCC version (4.7) doesn't seem to fit with the precompiled Qt binaries (MinGW 4.4). But that's a different thing. This one is solved. :)

    EDIT: Recompiled Qt 4.8.2 with MinGW GCC 4.7.0 and now everything works.

Log in to reply