PDA

View Full Version : qmake: Omit Qt libraries from PRL file



chenz
4th June 2012, 10:34
I'm building a library with qmake that should not depend on Qt at runtime. It does however contain some inline code that uses QString, and also uses Q_OS_XXX for platform detection.

The generated library does not import any symbols from Qt (I have checked with nm). The generated PRL file however pulls in QtCore.

If I add "QT -= core" to the project file, obviously compilation no longer works.

Is there any way to influence what gets written into the PRL file?

wysota
5th June 2012, 15:24
If you use QString then you are using Qt. If you want to disable linking with Qt, add "CONFIG -= qt" to your project file, however you'll see then that your project will not compile.

chenz
5th June 2012, 18:14
As I said, the QString-related code is inline only in the header file of my lib, it does not get compiled into the library.

I have turned off PRL generation now and manually wrote a PRI file containing the correct linker flags which I include in the projects using this library.

This is one of those instance where qmake is simply too specific to Qt I guess ;-)

wysota
5th June 2012, 21:26
As I said, the QString-related code is inline only in the header file of my lib, it does not get compiled into the library.
Which still makes your application depend on Qt since your users will have to link to Qt and they will not know why. It is better if your library links to Qt since it will inform your users explicitly about the requirements of your library.

chenz
6th June 2012, 09:41
The "users" do not have to link to Qt at all, because the inline QString code is also optional. And even if the application uses Qt, it could be a different version of Qt that the library does not even know about. In fact, I use this library (the same build) with both a Qt4 and a legacy Qt3 application.

ChrisW67
6th June 2012, 11:15
If your header includes Qt code and your library #includes that header then your library requires Qt to be present in order to compile.
If your header includes Qt code and your library user has to #include the header in order to use your library then they will require Qt in order to compile their program.

If the Qt code is conditionally removed by the pre-processor then I fail to see what your problem is. Compile your library with the Qt code removed by #define and don't link the Qt libraries. If you are using Qt to create a Makefile using


QT =

in the pro file will remove all reference to Qt during code generation and linking. Nothing to do with "PRL" files.

Example:


// lib.h
#ifndef LIB_H
#define LIB_H

#ifdef USE_QT
#include <QString>
inline int test() { return QString("abc").length(); }
#endif

struct Test {
int thingy(int val);
};

#endif



//lib.cpp
#include "lib.h"

int Test::thingy(int val)
{
return val * 2;
}



TEMPLATE = lib
TARGET = test
QT =
HEADERS += lib.h
SOURCES += lib.cpp



$ qmake
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4 -I. -o lib.o lib.cpp
rm -f libtest.so.1.0.0 libtest.so libtest.so.1 libtest.so.1.0
g++ -Wl,-O1 -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0.0 lib.o -L/usr/lib64/qt4 -lpthread
ln -s libtest.so.1.0.0 libtest.so
ln -s libtest.so.1.0.0 libtest.so.1
ln -s libtest.so.1.0.0 libtest.so.1.0

$ ldd libtest.so
linux-vdso.so.1 => (0x00007fffbf3ff000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f595a06e000)
libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6 (0x00007f5959d64000)
libm.so.6 => /lib64/libm.so.6 (0x00007f5959ae2000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f59598cc000)
libc.so.6 => /lib64/libc.so.6 (0x00007f595953d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f595a4bd000)