PDA

View Full Version : statically link Qt libraries (not build static library)



mcarter
1st February 2010, 17:24
I am currently working under linux, but eventually will need to so this in Windows.

I have seen many posts about statically linking Qt libraries, which turn out to be building static Qt library versions. I already have both the static and shared libraries. What is the magic in the '.pro' file to have qmake produce a Makefile that statically links the Qt libraries? And do this automatically.

If I modify the Makefile by hand and add '-Xlinker -Bstatic' before all the -lQt... and '-Xlinker -Bdynamic' after them, then the build process produces an app with statically linked Qt libraries.

And please do not tell me CONFIG items -static and -staticlib. From what I can see, they are for building a static library.

I haven't worked in Windows for a number of year, but I assume all that needs to be done there is choose the '.lib' files for the project since it does use the '.pro' file . . . even though it is based on it to start. It would be nice to be able to use one '.pro' file, though.

franz
1st February 2010, 18:36
Add


QMAKE_LFLAGS += -Xlinker -Bstatic

or


QMAKE_LFLAGS = -Xlinker -Bstatic $$QMAKE_LFLAGS

to your project file.

Check the qmake manual (http://doc.trolltech.com/4.6/qmake-variable-reference.html#qmake-lflags) for more information.

mcarter
1st February 2010, 20:06
adding -Xlinker command to QMAKE_LFLAGS does get it a step further, but that tries to statically link all libraries.

I just need the Qt libraries boxed with -Bstatic and -Bdynamic. The following

LIBS = $(SUBLIBS) -L/usr/lib/qt45/lib -L/usr/X11R6/lib -lutil -lQtOpenGL -L/usr/lib/qt45/lib -L/usr/X11R6/lib -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -lQtGui -pthread -lpng -lfreetype -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lXcursor -lXinerama -lfontconfig -lXext -lX11 -lQtNetwork -pthread -pthread -lQtCore -lz -lm -pthread -lgthread-2.0 -lglib-2.0 -lrt -ldl -lGLU -lGL -lpthread

changed to

LIBS = $(SUBLIBS) -L/usr/lib/qt45/lib -L/usr/X11R6/lib -lutil -Xlinker -Bstatic -lQtOpenGL -Xlinker -Bdynamic -L/usr/lib/qt45/lib -L/usr/X11R6/lib -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -Xlinker -Bstatic -lQtGui -Xlinker -Bdynamic -pthread -lpng -lfreetype -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lXcursor -lXinerama -lfontconfig -lXext -lX11 -Xlinker -Bstatic -lQtNetwork -Xlinker -Bdynamic -pthread -pthread -Xlinker -Bstatic -lQtCore -Xlinker -Bdynamic -lz -lm -pthread -lgthread-2.0 -lglib-2.0 -lrt -ldl -lGLU -lGL -lpthread

Not a biggee, but it would nice if qmake would cut down on the libraries inclusions ( I know I need pthread but that many times :-) )

franz
1st February 2010, 20:42
Maybe you need to muck about with the QMAKE_LIBS_* variables then. Be creative ;)