Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Statically linked program is trying to load a library on Linux
Forum Updated to NodeBB v4.3 + New Features

Statically linked program is trying to load a library on Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.1k Views 2 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.
  • N Offline
    N Offline
    nulluse
    wrote on 15 May 2016, 20:24 last edited by nulluse
    #1

    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?

    K 1 Reply Last reply 15 May 2016, 22:11
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 May 2016, 21:39 last edited by
      #2

      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
      0
      • N nulluse
        15 May 2016, 20:24

        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?

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 15 May 2016, 22:11 last edited by
        #3

        @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
        2
        • N Offline
          N Offline
          nulluse
          wrote on 17 May 2016, 23:46 last edited by
          #4

          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?

          K 1 Reply Last reply 18 May 2016, 09:52
          0
          • J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 18 May 2016, 04:22 last edited by
            #5

            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
            0
            • N nulluse
              17 May 2016, 23:46

              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?

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 18 May 2016, 09:52 last edited by kshegunov
              #6

              @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
              1

              3/6

              15 May 2016, 22:11

              • Login

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