Tuesday, 7 October 2014

Qt: Static and Dynamic linking for deployment of applications

Almost all software is developed using some pre-existing software, so that the developer doesn't need to invent the wheel again.

These pieces of software are imported in different manners to the final program. This may be:

  • Software that polls the keyboard and sends a corresponding character to the buffer/stdin,
  • Software that keeps track of the mouse pointer
  • Software that manages database connections
  • Software that sets up the user interface, such as the "Open file" window.
  • Software that handles networks
  • Software that handles databases
  • ...

In Windows, that code is compiled to DLL files (Dynamically Linked Library). Other operating systems such as Linux has similar libraries.

Put simply, In order to deploy  software and make it useful for others, there are two options: static and dynamic linking.

Static linking will bring the libraries into the exe file (~10-20 Mb). If many program files on a system will need the same libraries, there will be a lot of redundant code in the different executables.

Dynamic linking will make the program refer to DLL files for the needed external code. This results in a smaller exe files (~100kb), but that will be dependent on external DLL files. I'm sure that my readers has got their fair share of dll errors.

Text in Swedish, but the message is clear: 
spend hours chasing DLLs or consider another program.

The program Dependency Walker can be very helpful when finding what DLL files (and what versions) are needed for a program. Still, a lot of work and frustration lies ahead.

In the next blog post I'll describe what problems I saw when I tried building my program statically. Actually, I needed to recompile the entire Qt installation from its sources, and that's where I got the problems.

Until then, I can recommend VoidRealms/Bryan Cairns Youtube videos about DLL:s







No comments:

Post a Comment