Cannot link statically with MSVC2008.
-
wrote on 6 Nov 2011, 18:49 last edited by
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...
-
wrote on 6 Nov 2011, 19:00 last edited by
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":http://download.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.zip
Under step 4 in "this":http://developer.qt.nokia.com/doc/qt-4.7/install-win.html you find some hint for compilation under windows. -
wrote on 6 Nov 2011, 21:22 last edited by
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...) -
wrote on 6 Nov 2011, 23:01 last edited by
The linker usually detects automatically if a lib is dynamic or static.
-
wrote on 7 Nov 2011, 07:31 last edited by
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.
-
wrote on 7 Nov 2011, 08:47 last edited by
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...)
-
wrote on 7 Nov 2011, 09:14 last edited by
In Windows, for each .dll you need a corresponding stub .lib for linking. The .lib files in the SDK download are not static libraries!
-
wrote on 7 Nov 2011, 09:28 last edited by
OK, that explains why I can't use them as static libs...
-
wrote on 7 Nov 2011, 09:56 last edited by
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.
-
wrote on 7 Nov 2011, 09:56 last edited by
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? -
wrote on 7 Nov 2011, 09:59 last edited by
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.
-
wrote on 7 Nov 2011, 11:43 last edited by
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... :-)
-
wrote on 7 Nov 2011, 12:23 last edited by
Yes and yes :-)
-
wrote on 8 Nov 2011, 08:21 last edited by
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?
-
wrote on 8 Nov 2011, 08:50 last edited by
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? -
wrote on 8 Nov 2011, 08:52 last edited by
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 -
wrote on 8 Nov 2011, 09:01 last edited by
I have VC redist installed...
-
wrote on 8 Nov 2011, 09:38 last edited by
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 diagnosisSo 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?
-
wrote on 8 Nov 2011, 10:18 last edited by
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... -
wrote on 8 Nov 2011, 11:50 last edited by
THANK YOU!
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 :-)
1/21