Thursday, January 27, 2011

Finally got QT static linkage working! (How-to inside)

Yesterday I gave the current build of the leveleditor to a friend to test if the application runs correctly. He got an "Side-by-side configuration is incorrect" error when he wanted to start the editor.

After some investigation I found out that since VS2005 and Windows Vista you have to ship the Visual C++ Runtime library (Downloadlink see below) with your application to make them run properly.
(You'll notice the installation of the runtime files after you start nearly every game the first time in Valves Steam).

So you now have two choices...Either you ship your application with the runtime install files or you link the runtime library staticly to your application.Easy choice yeah...?

Well no. I was FORCED to find out that's it not that easy.

The tricky part is that every library you use in your application also has to be staticly linked with the runtime files.

So if you use foo.dll (DLL = Dynamic link library) and want to use it with your bar.exe but don't want the user to install the visual c++ runtime you'll have to compile foo.dll as foo.lib. To do that you have to open your DLL-project in Visual Studio and go to Project->Settings->Configurationsettings->Common. Set "Configurationtype" from "*.dll" to "*.lib" and choose "use MFC in a static library" at "Usage of MFC" after that go to "C\C++ -> Code generation" and change "Multithreaded Debug DLL" to "Multithreaded Debug" (Or "Multirthreaded DLL" to "Multithreaded" if you want to build a release).

If you've done that you do the same in your application project and then you are ready to go.

For QT-Developer:
If you want to staticly link Qt library you have to do the following:
  1. Download the OpenSource from the QT libraries.
  2. After you unpacked everything start the command prompt from Visual Studio.
  3. Go to the root directory of the unpacked sourcecode (the same directory where bin\ is in)
  4. Enter "configure -static" (during this process an project.sln will get created)
  5. Open Visual Studio and open the just created "project.sln"
  6. Choose the parts of QT you want to build and xo everything mentioned above to staticly link the runtime files.
If you've done that you should be able to staticly link the QT libraries.

If you don't want to link staticly, here you'll get the runtime installfiles:

No comments:

Post a Comment