Is it possible to build a completely static app using Qt 4 on Linux

After successfully statically compile Qt 4.6.3 under Unbuntu 10.04 Server, I tried to build static version fancybrowser, after some study, I got a static execute, but when ran it, it suspended before load url, I do not know why, after some search I got the following answer,

> Is it possible to build a completely static app using Qt 4 on Linux?

Completely static? No.

Almost completely static? Yes. The GNU Libc library’s NSS subsystem still
requires dynamic loading of some modules in order to fullfil your requests,
especially when it comes to DNS resolution. If you don’t use QTcpSocket or
QHostInfo, you probably will get a fully static binary though.

Make sure you have static libs for all Qt dependencies. They will be linked
into your executable, which will be several megabytes in size.

Better than that is to have Qt as a static library, but nothing else. That
will link Qt into your program, but will dynamically load the libraries it
needs from the system.

I believe that’s the approach that Skype uses on their static binaries.

> My problem is I’m trying to build an application that will run on a
> variety of recent (2.6.x kernel) distros. My first attempt (using shared
> libraries) results in “Floating point exceptions” when run on Debian. So
> now I’m looking at building statically.

My suggestion is to try the linux-lsb-g++ mkspec if you intend to deploy a Qt
application in several different Linux systems.

But I don’t see how floating point exceptions can have anything to do with the
Qt build. Maybe if you post a code sample and/or a backtrace of the crash, we

can help with that instead.

Be sure that you build your application on the “lowest common denominator”
platform of yours, since libc and libstdc++ are not forwards compatible
(i.e., you have to link to the lowest version you intend to deploy on).

This applies even if you replace the headers of those libraries with older
headers. (There’s a link-time dependency, whereas Qt is only compile-time)

> I was able to add a -static flag to my link flags in my .pro file, and
> I’m linking against static Qt libs, but when it gets to linking in
> libSM, it only finds the dynamic version and stops. I’m sure this is
> also the case for most of the X11 libraries.

Like I said above, you need to have the static library for all dependencies if
you want to have a fully static build.

> Can this be made to work? Or am I stuck building dynamically on a
> multitude of distros?

There’s always LSB.

The recently-announced LSB 3.2 contains Qt 4.2 as part of the required
standard. Any Linux distribution conforming to LSB 3.2 will have that. Most
recent Linux distributions already ship Qt 4.2 or even 4.3 (thanks to the KDE
4 release).

The previous LSB 3.1 standard contained Qt 4.1 but only as an optional module.
It has been out for close to 2 years now, though, so you may have a wider
variety of distribution targets.

Leave a Reply