From time to time, I have this moments when I cannot deploy my application properly and decide that I want to link it statically (then I generally give up, because it requires me to link the Qt libraries statically…). But is it really better to prefer static over dynamic linking?
As in so many other cases, it depends on what you want to do. I read that in terms of performance, there are trade-offs in both approaches, so in the end it really does not matter so much. From my point of view, the biggest advantage of static linking is the fact that you can ship one single file with your application, removing the risk of “broken” dependencies. That is, in terms of deployment, quite an advantage!
On the other hand, if everybody would link statically, we would literally have “thousands” of libraries “repeated” inside our system, packed inside “huge” binaries. It does not make much sense, does it?
Dynamic libraries are also “cool”, because we can (till a certain extent) replace them by newer (improved) versions, without having to recompile our application. That is like a huge benefit, in terms of “bug fixing” of third party libraries.
After removing the performance issue, my verdict would be:
- For myself, I would like to minimize resource consumption by using as much as possible, shared libraries (dynamic linking).
- For “bullet proof” systems, where users are not experienced in installing software, and are likely to “mess up” the system by removing parts of it, I would consider providing them statically compiled versions of the software, instead. The software will likely be “bigger “(although there are tools to minimize this, such as UPX), and a bit more “hungry” of resources, but this is also the only way to prevent the DLL hell.
Finally, it is important to mention that the type of linking may be conditioned by licensing issues. For instance due to the “nature” of the license, GPL libraries would “contaminate” any software statically linked with them.
For the record: Qt is really easy to link statically; here are the flags that I used:
./configure -static -prefix /usr/local/Trolltech/Qt-4.8.6_static -nomake examples -nomake demos -qt3support -qt-sql-odbc -qt-sql-psql -stl -release -no-phonon -no-dbus -no-phonon -no-phonon-backend -confirm-license -qt-libpng -qt-zlib -qt-libmng -qt-libtiff -qt-libjpeg
Pingback: Building Cross-plattform Applications (for real!) | heartcode