Results 1 to 6 of 6

Thread: qmake: Omit Qt libraries from PRL file

  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default qmake: Omit Qt libraries from PRL file

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qmake: Omit Qt libraries from PRL file

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qmake: Omit Qt libraries from PRL file

    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 ;-)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qmake: Omit Qt libraries from PRL file

    Quote Originally Posted by chenz View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qmake: Omit Qt libraries from PRL file

    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.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake: Omit Qt libraries from PRL file

    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 Code:
    1. QT =
    To copy to clipboard, switch view to plain text mode 
    in the pro file will remove all reference to Qt during code generation and linking. Nothing to do with "PRL" files.

    Example:
    Qt Code:
    1. // lib.h
    2. #ifndef LIB_H
    3. #define LIB_H
    4.  
    5. #ifdef USE_QT
    6. #include <QString>
    7. inline int test() { return QString("abc").length(); }
    8. #endif
    9.  
    10. struct Test {
    11. int thingy(int val);
    12. };
    13.  
    14. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //lib.cpp
    2. #include "lib.h"
    3.  
    4. int Test::thingy(int val)
    5. {
    6. return val * 2;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. TEMPLATE = lib
    2. TARGET = test
    3. QT =
    4. HEADERS += lib.h
    5. SOURCES += lib.cpp
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. $ qmake
    2. $ make
    3. 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
    4. rm -f libtest.so.1.0.0 libtest.so libtest.so.1 libtest.so.1.0
    5. g++ -Wl,-O1 -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0.0 lib.o -L/usr/lib64/qt4 -lpthread
    6. ln -s libtest.so.1.0.0 libtest.so
    7. ln -s libtest.so.1.0.0 libtest.so.1
    8. ln -s libtest.so.1.0.0 libtest.so.1.0
    9.  
    10. $ ldd libtest.so
    11. linux-vdso.so.1 => (0x00007fffbf3ff000)
    12. libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f595a06e000)
    13. libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6 (0x00007f5959d64000)
    14. libm.so.6 => /lib64/libm.so.6 (0x00007f5959ae2000)
    15. libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f59598cc000)
    16. libc.so.6 => /lib64/libc.so.6 (0x00007f595953d000)
    17. /lib64/ld-linux-x86-64.so.2 (0x00007f595a4bd000)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 21st April 2012, 10:36
  2. Replies: 2
    Last Post: 10th December 2010, 07:54
  3. How to link static libraries --- in .pro file settings?
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 7th January 2010, 16:39
  4. Replies: 2
    Last Post: 31st October 2009, 03:41
  5. qmake and libraries question
    By bnilsson in forum Qt Programming
    Replies: 4
    Last Post: 28th June 2008, 18:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.