LD_LIBRARY_PATH failing while trying to run Qt app

走远了吗. 提交于 2019-12-02 03:49:40

sudo doesn't pass LD_LIBRARY_PATH:

$ LD_LIBRARY_PATH=lib/
$ export LD_LIBRARY_PATH
$ env | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=lib/
$ sudo env | grep LD_LIBRARY_PATH

You can set it for the command run as root:

$ sudo env LD_LIBRARY_PATH=/lib env | grep LD_LIBRARY_PATH
SUDO_COMMAND=/usr/bin/env LD_LIBRARY_PATH=/lib env
LD_LIBRARY_PATH=/lib

You'll want something like

sudo env LD_LIBRARY_PATH=/lib "$INSPATH/myApp"

As always, be careful with sudo!

This is a real Linux problem. The best solution is to explicitly set the library locations in the executable, but that is not that simple.

Linux applications can be started when a so-called desktop file is created. All major software companies, like Google, create a desktop files of their product on the user's desktop or in the menu through an install script. The problem is that the desktop file needs the hard-coded location of the application. That means during installing this location must be interrogated and set in the desktop file. In addition the desktop file is a text file in which LD_LIBRARY_PATH cannot be set.

There is a workaround it. It does not win a beauty contest but it works. One can always start an application through a script and this script can set LD_LIBRAREY_PATH before running the application. But users might not like running/clicking an "application.sh" script. They expect to run it by double clicking on the application file. We solve this in the following way: when the script is executed we know the file location of the application. So we let the script first generate the desktop file and then execute the application. The desktop file executes the script. But as you can set the name and icon of the desktop file this becomes transparent to the user.

Final result is that the user has to click the shell script once and from then on a real application shortcut file can be clicked.

For details see.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!