Gnu/Linux set path to shared libraries



  • Hi all,
    On linux I used the precompile Qt /home/myuser/Qt5.9.3 All work fine.

    I want to deploy my application on other linux with Qt shared lib in my dirApp, but How to set path to shared libraries of my application ? through .pro file ? qt.conf ?

    Thanks



  • @cfdev
    I think the usual answer is to look at https://github.com/probonopd/linuxdeployqt.

    On linux I used the precompile Qt /home/myuser/Qt5.9.3 All work fine

    Do you mean you use the precompiled version of Qt that comes with your Linux distro, and is already compiled for you, or do you mean you compiled the Qt sources for yourself?

    I want to deploy my application on other linux with Qt shared lib in my dirApp, but How to set path to shared libraries of my application ? through .pro file ? qt.conf ?

    I don't use C++/QtCreator, but if you mean you run with shared Qt files in same directory as your app, and you intend that end users will do likewise, isn't the point that there is nothing to do, in .pro or .conf, the application will run finding those shared files in the same directory as its executable, without specifying a path?


  • Qt Champions 2017

    @JonB

    isn't the point that there is nothing to do, in .pro or .conf, the application will run finding those shared files in the same directory as its executable, without specifying a path?

    In Linux, you have to force the dynamic linker to search in the current directory for libraries due to security reasons:

    export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
    ./your_program
    


  • @aha_1980
    Oooohh, this is not Windows then! :)

    And people's LD_LIBRARY_PATH would not normally have . on it already?

    For the OP, I would have thought the .pro & .conf settings are not relevant to the end-user's run-time environment, he needs to look at deployment not compilation. Correct?


  • Qt Champions 2017

    @JonB as said, for security reasons '.' is not in the linker search path - as that makes it easy to inject malicious libraries.

    you can of course provide a script to run your program that way.



  • @aha_1980 said in Gnu/Linux set path to shared libraries:

    @JonB as said, for security reasons '.' is not in the linker search path - as that makes it easy to inject malicious libraries.

    But just so I understand: LD_LIBRARY_PATH is just a user runtime environment variable which any user can set however they like? So how does that contribute to security?


  • Qt Champions 2017

    @JonB said in Gnu/Linux set path to shared libraries:

    But just so I understand: LD_LIBRARY_PATH is just a user runtime environment variable which any user can set however they like? So how does that contribute to security?

    That's an interesting question. I surely cannot answer it completely, but here are my thoughts:

    1. You never have '.' in the library search path, and it's easy to check if it is. If you do, you're on your own.
    2. It may be easier to inject a library file (e.g. through a shared folder) than modifying someone elses environment (though not impossible).
    3. Programs can clean the environment at startup, and I know some of them do so (especially those which run with elevated rights)

    Back to topic:

    For the OP, I would have thought the .pro & .conf settings are not relevant to the end-user's run-time environment, he needs to look at deployment not compilation. Correct?

    I'd say yes. I don't know how linuxdeployqt works but that is definitely worth a look.


  • Moderators

    @JonB For same reason . is usually not in PATH: if someone manages to put an executable for example in your home directory named "grep" and you then type "grep" in console while your current directory is your home this "bad" grep will be executed instead of the correct one. Sure, user can add . to PATH or LD_LIBRARY_PATH, but then it is up to the user. The default configuration should be as secure as possible.


  • Moderators



  • @aha_1980 said in Gnu/Linux set path to shared libraries:

    You never have '.' in the library search path, and it's easy to check if it is. If you do, you're on your own.

    OK, so it's a "user beware" protection. I come nowadays from a Windoze background, the thought that security could rely on what an environment variable might be set to would be strange there! And of course the first place it looks for a DLL, automatically, is in the same directory as the executable!


  • Moderators

    @JonB Why would it be strange? If user changes something then it is up to him/her. Linux/UNIX gives you freedom with reasonable default configuration. If you change something then you're responsible.
    And Windows is not the most secure OS out there :-)
    LD_LIBRARY_PATH=. does not mean same directory as executable, but current directory what ever it currently is



  • @JonB said in Gnu/Linux set path to shared libraries:

    linuxdeployqt.

    I had try LinuxDeployqt but it's so buggy, with sql my application crash.

    With ldd command, I see my application search lib in the install Qt directory... I want to create an app directory standalone if possible.

    Like QtCreator I try to create an qt.conf file with :

    [Paths]
    Prefix=lib/Qt
    Libraries=lib
    Plugins=plugins
    

    But when I run my app, he tell me :

    $ ./mApp
    This application failed to start because it could not find or load the Qt platform plugin "xcb"
    in "".
    
    Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
    
    Reinstalling the application may fix this problem.
    Abandon (core dumped)
    
    

    Strange because he found the libs available, if I change the path, he tell me not available...



  • @cfdev said in Gnu/Linux set path to shared libraries:

    I had try LinuxDeployqt but it's so buggy, with sql my application crash.

    Well that's a bit worrying, because so far as I know that is what anybody has to use to deploy Qt applications under Linux...

    I take it you have read http://doc.qt.io/qt-5/linux-deployment.html


  • Moderators

    @cfdev Please execute

    ldd YOUR_APP_DIR/plugins/.../libqxcb.so
    

    Is there any dependency not found?



  • @jsulm Ok thanks, libs are missing by xcb plugin. :)
    After I had a problem with Qt WebEngine

    my qt.conf

    [Paths]
    Prefix=lib/Qt
    Libraries=lib
    LibraryExecutables=libexec
    Plugins=plugins
    Translations=translations
    

    And When I run my application:

    $ LD_LIBRARY_PATH=lib/Qt/lib ./mApp
    Qt WebEngine ICU data not found at /home/cfdev/Qt5.9.3/5.9.3/gcc_64/resources. Trying parent directory...
    Qt WebEngine ICU data not found at /home/cfdev/Qt5.9.3/5.9.3/gcc_64. Trying application directory...
    Qt WebEngine ICU data not found at /home/cfdev/mApp/lib/Qt/libexec. Trying fallback directory... The application MAY NOT work.
    Path override failed for key base::DIR_QT_LIBRARY_DATA and path '/home/cfdev/.QtWebEngineProcess'
    
    

    Solution: I copy all ressources file of QtWebEngine in libexec dir and It's ok :) !



  • @cfdev if your issue is solved, please don't forget to mark your post as such. Thanks.



  • Ok many thanks all ! solved


Log in to reply
 

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