How to set library path for qtcreator in Ubuntu ?
-
Hi, I develop software with QtCreator 4.10.2 on Ubuntu 18.04.
It works greatly.The project is managed by cmake. and the qt version is 5.9.
But I encountered problems when I tried to debug the program.
The message in "Application Output" is
error while loading shared libraries: ***.so: cannot open shared object file: No such file or directory
But
-
If I started the program from terminal, the program works normally
-
I tried to clear build-directory of project and delete *.user in source directory, but the problem still exists when I rebuild project from source
-
I manually add library paths into
PATH
inProjects->Run->Run Environment
, it still doesn't work. -
I manually add library paths in to
Kit
configurations, it still doesn't work. -
If manually add
LD_LIBRARY_PATH
inProjects->Run->Run Environment
, it works.
So, What should I do to let qtcreator load
LD_LIBRARY_PATH
automatically ? -
-
Hi,
One way is to start it from the console where you defined that variable.
However if you defined it system wide, it should be picked up automatically unless you modified the environment.
Note that PATH has nothing to do with library loading on Linux. It's only for executable discovery.
-
How did you set that variable ?
By the way, what is that library ? -
@SGaist my project requires some 3rd libraries to run. Such as qt, vtk, and etc.
First, I setLD_LIBRARY_PATH
in~/.bashrc
, which doesnot work, just as I explained before
Then, I manually addLD_LIBRARY_PATH
in (current open project of QtCreator)Projects->Run->Run Environment
, it works. Just as step 5 shown.I start QtCreator from
Ubuntu dock
.
Can this be the reason ? -
@laine said in How to set library path for qtcreator in Ubuntu ?:
I set LD_LIBRARY_PATH in ~/.bashrc
Can you show how exactly you're doing this?
-
@jsulm I set with following code in
~/.bashrc
export PATH=$PATH:~/libraries/qt-5-91/5.9.1/gcc_64/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/libraries/qt-5-91/5.9.1/gcc_64/lib export QTDIR=~/libraries/qt-5-91/5.9.1/gcc_64
By the way, if I start qtcreator from shell, it works.
-
Personally I advise against using LD_LIBRARY_PATH in any situation. Here is an example of why you should not do this. At work we use an in house build of GCC that is badly done and relies on LD_LIBRARY_PATH. If I use our standard setup, then I can't execute qtcreator because there is a conflict in the versions of libstdc++ caused by our LD_LIBRARY_PATH. If I unset LD_LIBRARY_PATH, I can run qtcreator fine. But then when I try to build any software, our tools that need their LD_LIBRARY_PATH don't work. In this case I can add the LD_LIBRARY_PATH to the build environment. Alternatively you end up with each app being launched with a wrapper script that sets LD_LIBRARY_PATH.
There is a better way. RPATH. See this topic on SO. Effectively this bakes in the correct library search path into your executable.
-
@laine
I don't know if this is your problem/you are already aware, but do you understand that.bashrc
is not always read? It's only read in whenbash
is started interactively (like a terminal shell). Do you need to check if your.profile
/.bash_profile
issource
-ing it?