Results 1 to 3 of 3

Thread: Merging static libraries in a shared library with qmake -- empty result

  1. #1
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Merging static libraries in a shared library with qmake -- empty result

    I am using qmake to build a project that consists of two applications (say A and B). In order to keep the structure clear, I divided the project in components using a subdirs template for the top level .pro file. Those components can be partitioned in three groups:
    1) those that will be used by application A only,
    2) those that will be used by application B only,
    3) those that will be used by both.

    I would like to build all components in group 3 as static libraries, then combine them in a large shared library that applications A and B would link to. I have not found anywhere how to achieve that with qmake. If I try something along the lines of
    Qt Code:
    1. TEMPLATE = lib
    2.  
    3. CONFIG += shared
    4.  
    5. LIBS += \
    6. -lComponent_1_built_as_static_lib \
    7. -lComponent_2_built_as_static_lib \
    8. ...
    9. -lComponent_n_built_as_static_lib
    To copy to clipboard, switch view to plain text mode 
    where Component_1_built_as_static_lib, ..., Component_n_built_as_static_lib are the static libraries corresponding to the components in group 3, I do get a shared library but it is empty; linking applications A and B obviously fails with unresolved symbols.

    My guess is that the linker only picks what it needs from Component_1_built_as_static_lib, ..., Component_n_built_as_static_lib when building the shared library, but that library does not contain source files itself. Therefore I end up with nothing. How can I force qmake to act dumb and pick everything instead?

    For the record, I use Qt 4.6.3 with gcc 4.4.5 and Linux 2.6.32.

    Best regards, Olivier.

  2. #2
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Merging static libraries in a shared library with qmake -- empty result

    I think you are guessing right as to the cause (linker reference optimization). The right answer (IMO) is to build the shared library directly from source of group 3. You can try forcing the linker to resolve a symbol (for instance taking the address of an external function or declaring reference variable for external class). This doesn't necessarily have to work, though. Once the linker sees that the symbol is not being referenced by something that the library itself is exporting, there's no reason that it cannot just drop it.

  3. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Merging static libraries in a shared library with qmake -- empty result

    Thanks, Timoteo. I ended up building the shared library from source, which solved the issue. Alternatively, in order to force the linker to export some classes I was thinking of simply defining factory functions for them in the library.

Similar Threads

  1. Can I link shared library in static build program?
    By berlinud in forum Installation and Deployment
    Replies: 1
    Last Post: 27th August 2010, 16:36
  2. statically link Qt libraries (not build static library)
    By mcarter in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2010, 20:42
  3. Qmake fails to set shared library dependency
    By jkv in forum Qt Programming
    Replies: 5
    Last Post: 3rd September 2009, 13:44
  4. qmake: dependency of application on common shared library
    By PeterWurmsdobler in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2009, 16:13
  5. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33

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.