Cannot link statically with MSVC2008.

  • Hi,
    I'm building an application with QtCreator and Microsoft Visual Studio 2008 as compiler. It works fine on my machine where I have everything installed. But I would like my binary (.exe) to run on another computer. I copied the .exe and the .manifest file, but when starting the program it wants to load some Qt DLLs.

    I would like to build my application with the static Qt libs (.LIB) but I can't make it work. I defined CONFIG += static in the .pro file, but no...

  • Moderators

    Did you compile Qt for static libs?
    If you have downloaded some binaries you have only a dll-compiled version. For static libraries you need to compile the whole source yourself.
    For windows you have to download "this zipped version":
    Under step 4 in "this": you find some hint for compilation under windows.

  • OK thanks, I'll try that.
    But I don't understand how re-compiling Qt can help me so that the MS command link.exe use static libs instead of dynamic? (On the other hand, I cannot find a "static link" flags/option for link.exe either...)

  • The linker usually detects automatically if a lib is dynamic or static.

  • The dlls you get from Nokia as precompiled libraries are only dlls, not static libraries. If you need static libraries, you have to build them.

    This means you have to call configure.exe from the source tarball with the static flag.

  • Hmm, OK. But there are alot of .LIB files as well in the SDK I've installed. Why can't I use them?
    I even tried to remove the DLLs, hoping the linker should take the LIBs instead. But no...

    (BTW, I'm currently building Qt static as koahnig suggested, it has already taken 5-6 hours in my Virtual VMWare Windows 7 and is not ready yet...)

  • In Windows, for each .dll you need a corresponding stub .lib for linking. The .lib files in the SDK download are not static libraries!

  • OK, that explains why I can't use them as static libs...

  • Oh, and be aware of license implications when using static libs!

    If you use the (L)GPL version of Qt, it's most likely that you need to release the source code of your application under GPL too (I'm not a lawyer, so do your own research beforehand!). If you do not want to release your source code, you will be in need of a commercial license.

  • Another thing. My compilation of Qt became so big I ran out of disk... :-(
    I will create a new VM with bigger disk and start over.
    My question is, if I compile Qt 4.7.4 do I need the SDK at all? Or do I get "my own" SDK when I build Qt?

  • The SDK consists of the Qt libs itself ("Qt") and additional tools, like Qt Creator, a free toolchain (MinGW) - if you choose that.

    So, basically no, you do not necessarily need the SDK. Qt Designer, Assistant, Linguist, etc. are part of the libs. Qt Creator can be downloaded separately.

  • So I get all I need (static libs and MSVC2008 tool chain) from compiling Qt 4.7.4, except Qt Creator?
    BTW is "Qt lib" & just "Qt" the same thing?

    Sorry for newbie questions... :-)

  • Yes and yes :-)

  • I've built Qt (lib), installed Qt Creator, and when I try to build my application it cannot find the Windows SDK LIB-files. I can see them in the file system (But Qt cannot). What is the best way to add LIB path? In my .pro-file, in the mkspec-file or declare an environment variable?

    Or should I try to make Qt Creator run the MSVC2008 vcvarsall.bat setup file?

  • My mistake! I had the MinGW tool chain specified, should be MSVC2008...
    Now my exe file is 13 MB instead of the 35 kB it was when I linked it dynamically. 13 MB sure sounds as if I have built-in the static libs which was my goal!
    But when I try to run it on a machine where Qt is not installed, I get "The application has failed to start because its side-by-side configuration is incorrect..."
    Maybe my build was unsuccessful after all?

  • Then perhaps the VC redist are missing.
    I'm not 100% sure, how to link them statically.
    This is msvcrt*.dll etc which is installed inside the windows directory in SxS

  • I have VC redist installed...

  • But it does seem to have something to do with the redist. The Event Log says (dummyTest.exe is my program...)
    Activation context generation failed for "D:\tools\qttests\test1\dummyTest.exe". Dependent Assembly Microsoft.VC90.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" could not be found. Please use sxstrace.exe for detailed diagnosis

    So I unistalled the VC redist, rebooted, and installed the VC redist again. Same fault. And the version 9.0.21022.8 from the log post matches exactly the redist version. What else is there to do?

  • which version of redist?
    debug redist are never installed!
    use the release build on that machine and it should work.
    Debug versions are never meant for distribution...

    As you say (Gerolf) I made a Debug build, but with a Release build I can run it on another machine than the one I built on.
    Thanx again! Now I'm happy :-)

  • [quote author="Gerolf" date="1320747501"]which version of redist?
    debug redist are never installed!
    use the release build on that machine and it should work.
    Debug versions are never meant for distribution...[/quote]

    Not only that they are not meant for distribution, but Microsoft does not allow you to do so!

Log in to reply

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