PDA

View Full Version : Linker fails to use static QT libraries it uses shared libraries



Nuff
3rd November 2011, 18:46
I currently have two installations of QT on my linux machine. The shared version is installed in /opt/QTSDK/Desktop and the static version is installed in /usr/local/Trolltech.

I am also using the mysql plugin.

How do I get the linker during the build of my executable in Netbeans to use the static XX.a libraries and not the shared XX.so libraries?

Also do I need to make any modifications to my xx/xx/xx/xx/Release/program.pro file or will that automatically be generated with " CONFIG +=static" and "QTPLUGIN += qsqlmysql " keywords once Netbeans sees I am building a static executable?

Thanks in advance.

ChrisW67
3rd November 2011, 22:12
Use the qmake from the Qt install that you wish to link to and the Makefile should be correctly built.

Nuff
4th November 2011, 15:24
I am using the qmake from the static version but the executable being built contains shared libraries from /usr/include. /usr/include has both X.a and X.so libraries and it appears the linker grabs the .so files first.

How does Netbeans know it is building a static version? Is there a way to force the linker to build a static version.

Nuff
4th November 2011, 15:30
BTW, further review using the ldd command seems to indicate that all my QT installation files appear to be getting loaded in static form. The libraries which are suspect and which appear to be getting loaded shared are the libraries in the /usr/lib and td /lib/tls/i686/cmov directories.

In the /usr/lib directory there is a compatible XX.a library for each xx.so library. But the xx.so libaries are getting loaded and not the xx.a libraries.

Here are some of the libraries which are getting loaded shared instead of static from /usr/lib

/usr/lib/libmysqlclient.so.15
/usr/lib/libSM.so.6
/usr/lib/libICE.so.6
/usr/lib/libfontconfig.so.1
/lib/tls/i686/cmov/libdl.so.2
.
.
.
/lib/libgcc_s_so.1

ChrisW67
5th November 2011, 01:38
Those are the dependencies against which Qt has been built. In many cases there will not be a static version of those libraries present on your system unless you go out of your way to generate one. I am not sure if it is possible, or even desirable, to try to build everything into your single executable. Certainly you would not bother with libc in most cases.

If you are using the GNU compiler then you could experiment with the "-Bstatic" option but you will have to find a way to stop qmake inserting a "-Bdynamic" (you can probably see that in the Makefile now). I've never tried this myself. Perhaps someone else has.