Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [Solved]How can I properly force my Qt Application to loads shared libraries from Certain Directory when it loads?
Forum Updated to NodeBB v4.3 + New Features

[Solved]How can I properly force my Qt Application to loads shared libraries from Certain Directory when it loads?

Scheduled Pinned Locked Moved Installation and Deployment
11 Posts 4 Posters 9.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    setLibraryPaths() will not solve your problem. That method changes default lib paths for libraries loaded after your application starts (plugins, or stuff loaded with QLibrary).

    But Qt libraries (and all other DLLs) are required before the application starts, and are being loaded by your OS. So, that part is handled by the operating system and you have no control over it in your application.

    The solution is indeed to use a shell script with LD_LIBRARY_PATH or similar approaches. I know you would rather not do that, but your other possibility in this case is not to distribute your application at all ;)

    (Z(:^

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sunsina
      wrote on last edited by
      #3

      I even tried following shell script and I took out those lines of code
      which sets the library path.

      Then I made following shell script and I checked it that in fact it did not made any changes.

      @#!/bin/bash
      export LD_LIBRARY_PATH="pwd/Qtlibs"
      echo ${LD_LIBRARY_PATH}
      ldd ./QtProjectWork $*
      @
      So still the libraries are downloaded from the opt/Qt/.... directory.
      I am wondering if I can set any variable in .pro file to solve the problem.

      Otherwise I have to compile the code and use it as static library (that I do not know how?).

      In fact in Linux Mint/Ubunutu LD_LIBRARY_PATH is not defined !?.
      I checked /etc/ld.so.conf.d contents which stores the library paths and I could not find and PATH which points /opt/Qt/5.2.1/..... libraries path that was strange (where the Qt libraries paths are defined ?) and how the system looks for it.
      If none of the solution works I have no other alternatives to compile it as static that I have to figure out how :-(

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #4

        LD_LIBRARY_PATH is always empty: this is exactly so that you can set it yourself in your scripts :) I definitely use it on Kubuntu and it works. You can also check the bin dir of Qt Creator: they are using the same trick.

        If you want to be sure, rename your Qt folder to /opt/Qt-blahblabhblah and then try to run your application with and without the script.

        (Z(:^

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #5

          "Here":http://www.tripleboot.org/?p=138 you can find great blog about solving this issue from "hskoglund":https://qt-project.org/member/131157 .

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sunsina
            wrote on last edited by
            #6

            Thanks qxoz,
            I think the chrpath command that I have to use does not need to be installed on the user's machine (please note that user can not install anything) but I can apply on the binaries in advance [I guess the chrpath changed the binary contents and I do not need to change LD_LIBRARY_PATH in script file?] but I can not figure out how can I change the $ORIGIN to something like ./Qtlibs since I want the libraries reside in one directory after the executable not the same directory that the executable is.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #7

              Unfortunately i am more windows user and i am afraid can't give you useful advice :( .
              By the way "Qt SDK":https://qt.gitorious.org/qtsdk installer also do something like that.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sunsina
                wrote on last edited by
                #8

                Thanks to qxoz and sierdzio I have followed the [tripleboot.com] guidelines
                it seems all the problems are solved by using chrpath since it modifies the binaries and change the runtime library path.

                In fact I have used following command to make it work in linux :
                $chrpath -r ./Qtlibs QtProjectWork
                it seems that it has modified the binary (checked with md5sum) and the
                ldd QtProjectWork could be used as single binary with all the Qt5 libraries installed in [EXEC_PATH]/Qtlibs ---> I got no issues with ldd on missing libraries and the issue is solved. :-)

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #9

                  Thanks for sharing the solution with us, I have learned something too :)

                  (Z(:^

                  1 Reply Last reply
                  0
                  • hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on last edited by
                    #10

                    Hi, just saw this thread, great that my blog is helping! I am lazy but I promise more blog posts, like, more on deployment, how to fix Qt's ODBC for Linux/Mac and how to write a QtCreator plugin.

                    EDIT: forgot, $chrpath -r ./Qtlibs QtProjectWork is a pretty clever idea, makes for less clutter in the app's main directory. And I should mention in the blog, you can indeed do chrpath in advance on your dev. machine.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sunsina
                      wrote on last edited by
                      #11

                      Thanks hskoglund for your great blog.

                      I would rather to use relative paths instead of absolute due to following reasons:

                      1 - Different versions of an application on a single machine does not crash when there is a version mismatch between their shared libraries (which only happens if their rpath is not relative path).

                      2- Access privileges issues for different machines and type of users, user might not get enough privileges to copy and install shared libraries in certain path on the system.

                      3- Ease and comfort in replacing or upgrading libraries without disturbing other applications that are using the very same shared library, one might imagine the huge differences between libQtCore5.so symbol link if it points to different versions of actual shared libraries such as libQtCore.so.5.0.2 or libQtCore.so.5.2.1 .

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved