Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Statically linked program is trying to load a library on Linux

    General and Desktop
    4
    6
    1695
    Loading More Posts
    • 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.
    • nulluse
      nulluse last edited by nulluse

      I added CONFIG += static to the .pro file but when I run the console opens instead of the program and says

      /home/user0/Compile/MandelbrotQt/MandelbrotQt: error while loading shared libraries: libOpenCL.so.1: cannot open shared object file: No such file or directory
      Press <RETURN> to close this window...
      

      That library was added to the .pro file as well:

      unix:LIBS += /opt/AMDAPPSDK-3.0/lib/x86_64/sdk/libOpenCL.so
      

      How can I statically link against that library too?

      kshegunov 1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You would need to also have a static version of that library.

        Since your libOpenCL is located in a non-system folder, you should modify the LD_LIBRARY_PATH environment variable so the loader can find it.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • kshegunov
          kshegunov Moderators @nulluse last edited by

          @nulluse
          For the long explanation on static libraries see here.
          In few words:
          You either provide the application with the link line for the .so you've used in your static library, or compile that external dependency as a static library and statically link it.

          You've used the first approach, which is commendable, but as @SGaist pointed out the loader can't find your .so library, so you have 2 options again.

          1. Either start your app with:
          LD_LIBRARY_PATH=/opt/AMDAPPSDK-3.0/lib/x86_64/sdk:$LD_LIBRARY_PATH ./yourapplication
          
          1. Or set the rpath field of the ELF header (but only to a location that'd contain your library when executed - usually the same directory the app is residing in):
          QMAKE_RPATHDIR += $ORIGIN
          

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply Reply Quote 2
          • nulluse
            nulluse last edited by

            After linking the library to the build folder I am getting new errors at runtime:

            $ ./MandelbrotQt
            ./MandelbrotQt: error while loading shared libraries: libicui18n.so.56: cannot open shared object file: No such file or directory
            

            What needs them and why don't they get installed with Qt if they are required?

            kshegunov 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion last edited by

              This library is installed together with Qt. You have to provide it together with your application if you deploy it.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 0
              • kshegunov
                kshegunov Moderators @nulluse last edited by kshegunov

                @jsulm

                This library is installed together with Qt. You have to provide it together with your application if you deploy it.

                It's not so simple on Linux. It won't resolve by just copying the .so in the application folder, as it would on Windows.

                @nulluse said:

                What needs them

                QString and everything string related; this is the unicode support.

                why don't they get installed with Qt if they are required?

                They should be installed with Qt. Depending on how exactly you obtained your Qt distribution, they're either in the Qt installation directory (which I believe is your case, because it looks like you used the maintenance tool), or they are in the system libraries folder (/lib, /usr/lib, etc. if you used your OS distribution's repository).

                The Qt binary you get from the maintenance tool doesn't set the rpath (which is quite correct, because there's no beforehand knowledge how you will deploy). You either copy the library to your application folder and set the rpath header field manually or use $LD_LIBRARY_PATH.

                You can change the rpath for the Qt library with patchelf. For example if you're deploying everything in your application folder:

                patchelf --set-rpath '$ORIGIN' Qt5Core
                

                Resolving these should make the loader stop complaining.

                PS.
                You can inspect on which libraries you need to set the rpath by checking their dependencies. For example for the Qt core module:

                readelf -d Qt5Core
                

                PS 2.
                This also might be of use:
                http://doc.qt.io/qt-5/linux-deployment.html#shared-libraries

                Kind regards.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post