Statically linked program is trying to load a library on Linux



  • 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?


  • Lifetime Qt Champion

    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.


  • Qt Champions 2016

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



  • 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?


  • Moderators

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


  • Qt Champions 2016

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.