Results 1 to 5 of 5

Thread: Changing Qt Lib Paths

  1. #1
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Changing Qt Lib Paths

    I performed the standard Qt SDK install, and my binaries produced show
    paths to the Qt libraries as /home/QtSDK/etc as revealed by entering the
    ldd command under Linux. I am building within Qt Creator using a .pro
    file.

    As a result, check paths under Linux when building an RPM detects this
    absolute path as an error.

    For my distribution, I intend to use an RPM to copy two Qt libraries
    to /usr/lib64 on a target machine that will not have Qt installed on
    it.

    While I have changed the LD_LIBRARY_PATH within the QtCreator IDE,
    the binaries produced continue to reference my local home SDK install.

    I would like this to be the /usr/lib64 pathname where the libraries
    are also stored.

    Is there a easy way to do this?

  2. #2
    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: Changing Qt Lib Paths

    The easy way to do it is to build using the system Qt4 (i.e. use its qmake) rather than the one you are using so that the RPATH/RUNPATH are "correct".

    Alternatively, you can force the RPATH using your PRO file:
    Qt Code:
    1. QMAKE_LFLAGS_RPATH="-Wl,-rpath,/some/other/location"
    2. # or remove it completely
    3. QMAKE_LFLAGS_RPATH=
    To copy to clipboard, switch view to plain text mode 
    You can also remove the RPATH/RUNPATH from your executable after it is built using a utility "chrpath".

    The rules for locating libraries can can be found in:
    Qt Code:
    1. $ man ld-linux.so
    To copy to clipboard, switch view to plain text mode 
    but you have to temper that with some "What actually happens" information: http://labs.qt.nokia.com/2011/10/28/rpath-and-runpath/

    Qt builds executable with both DT_RPATH and DT_RUNPATH set by default. You can see that in the output of:
    Qt Code:
    1. readelf -d programexe
    2. ...
    To copy to clipboard, switch view to plain text mode 
    With both set, RPATH is ignored and the dynamic linker will use LD_LIBRARY_PATH, the RUNPATH embedded locations, and the system locations in that order. This is why the Creating the Application Package instructions use a script to ensure that a set of Qt libraries bundled in the application directory are found first. If you don't use LD_LIBRARY_PATH and the RUNPATH does not exist on the target then the system locations will be searched for needed libraries.

    You should be aware to writing your application Qt libraries into system location may cripple any system Qt installed on that machine. If you want a system Qt on the machine I suggest you use the system's package manager to install a compatible version.
    Last edited by ChrisW67; 20th April 2012 at 00:24.

  3. #3
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Changing Qt Lib Paths

    Chris, thanks for the detailed response, I will give your suggestions a try.

    The motivation for distributing two Qt files (and symlinks) is because for the legacy platforms that I need to support, the latest package manager version of Qt is not very recent, e.g 4.6 rather than say 4.8.1, the current.

    I am also considering using static linking to avoid any potential collisions, but am certainly open to ideas on best practices.

    The deployment will be for a dedicated platform on say RHEL 6, so the platform itself is not generalized for other use.

    However, I do want to be a good workstation citizen, and am open to other ideas.

    The platform will not have net access, so the install must be from my installation media, and it is less desirable to install the entire SDK when I only need two shared libraries.

    Static linked was the other consideration.

    Is there any notion of the Qt libraries being backwards compatible, in the event I replace say a symLink to v4.6 with on to v4.8.1?


    Added after 16 minutes:


    I should mention that my application is a Linux daemon that is invoked at system boot and run as root and hence some of the solutions that use LD_LIBRARY_PATH may not be applicable.
    Last edited by bob2oneil; 20th April 2012 at 05:06.

  4. #4
    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: Changing Qt Lib Paths

    For an application running setuid or setgid LD_LIBRARY_PATH will be ignored. A non-setuid application running as root will probably honour it.

    There is a magic value, $ORIGIN, you can use on the RPATH/RUNPATH that will cause it to look for libraries in a directory relative to the location of the executable. You can get it this way:
    Qt Code:
    1. # suppress the default RPATH if you wish
    2. QMAKE_LFLAGS_RPATH=
    3. # add your own with quoting gyrations to make sure $ORIGIN gets to the command line unexpanded
    4. QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
    5. # or for a subdir of your install
    6. QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/libs\'"
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. $ readelf -d simple example | grep PATH
    2. 0x000000000000000f (RPATH) Library rpath: [$ORIGIN]
    3. 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN]
    To copy to clipboard, switch view to plain text mode 

    Applications requiring 4.6.1 should run with 4.8.1 libraries, but not the other way around.
    Last edited by ChrisW67; 20th April 2012 at 05:53.

  5. #5
    Join Date
    Nov 2010
    Posts
    122
    Thanks
    62
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Wink Re: Changing Qt Lib Paths

    Thanks Chris, this gives me some ideas on the options that are possible. It would seem that the process of installing via an RPM two
    Qt libraries does come with some complications, which is why in my case, static linking is a possibility. Currently I am installing via
    RPM my daemon to /usr/sbin consistent with Linux conventions for daemons, and I intended to distribute 2 Qt libraries to
    /usr/lib64 consistent with the nominal Qt install. The fact that this is not a generalized deployment, but one for a specific
    RHEL 6 64-bit platform whose use is for my application alone does give me some latitude. The fact that a 4.8.1 deployment will support
    apps using the platform official Qt distro of 4.6, that is 4.8.1 is backwards compatible is very encouraging. It would seem then
    by potentially updating the platform and replacing the symbolic links, no damage should be done.

    Are you advocating that the 2 Qt libraries, QtCore and QtNetork be placed in /usr/sbin along with my root owned application,
    perhaps a different folder for all 3 components, perhaps a static build that eliminates the need for the Qt deployment, or
    perhaps just giving me an education on the possibilities?

Similar Threads

  1. Relative paths in Qt
    By drmath in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2010, 16:50
  2. Replies: 2
    Last Post: 10th August 2009, 09:45
  3. include paths
    By altec in forum Installation and Deployment
    Replies: 0
    Last Post: 8th August 2008, 11:59
  4. Problems with paths
    By zorro68 in forum Installation and Deployment
    Replies: 1
    Last Post: 13th July 2008, 11:20
  5. How to set paths?
    By hoborg in forum Installation and Deployment
    Replies: 11
    Last Post: 24th February 2006, 19:08

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
  •  
Qt is a trademark of The Qt Company.