Issue loading shared library - linux

I have a shared library and application in same folder and when I try to open terminal from that folder and run the application it gives library not found issue. If i set environment variable $LD_LIBRARY_PATH then it works well
My question is:
Wouldnt opening the terminal from that folder sets environment variable $LD_LIBRARY_PATH?

Wouldnt opening the terminal from that folder sets environment variable $LD_LIBRARY_PATH?
No, you will have to add it to your $LD_LIBRARY_PATH
Basically the shared library's location is not in the linker's search path. You will have to either
modify the LD_LIBRARY_PATH environment variable and then run ldd again or
move the shared library file to one of the $LD_LIBRARY_PATHalready present

Related

Error while loading shared library : librun.so

I have a compiled script (it's some utility) and the source code of which is unavailable. As soon as I run the script this error shows up:
error while loading shared libraries: librun.so: cannot open shared object file: No such file or directory
I have faced these kind of errors in past which had different solutions. I tried all as per my knowledge and..
librun.so is there in lib folder of my application
It is symbolic link and pointing to correct version
librun.so is available in path variable
changed .profile to look for the required library
changed permissions and checked
"which librun.so" is also returning the presence of that library
still this error shows up.
What can be the reason for this problem?
The dynamic linker is unable to find librun.so during runtime linking of shared libraries. Try adding the path of directory containing librun.so to the LD_LIBRARY_PATH environment variable when starting the application script.

How does processes find shared libraries in folders under /usr/lib

Assume that a program needs a shared library(bar.so) under the folder /usr/lib/foo. I understand if the bar.so was directly under /usr/lib, it would be automatically found. But as in my case the library could not be found automatically, because -I think so- it is under the folder /usr/lib/foo. However there are tons of other folders under /usr/lib and the corresponding programs using those libraries are working seamlessly.
So, how does this process work and how can I fix my issue?
Thanks.
Individual programs can control where they search for their libraries.
Also the search path can be controlled using the LD_LIBRARY_PATH env var:
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
Try appending /usr/lib/foo to your LD_LIBRARY_PATH env var.

uic can't find shared library

I am trying to make a Qt5 part of my source tree, so I haven't installed it on my machine, just copied it from source control. I am having a problem when I try to run uic.exe:
stiopa#stiopa-VirtualBox:~/ct/LinuxLibs/Qt/bin > ./uic
./uic: error while loading shared libraries: libQt5Core.so.5: cannot open shared object file: No such file or directory
I am still getting the same error even when I copy the libQt5Core library to bin directory. How is uic looking for shared libraries? Is there any environment variable I need to set to fix it?
This is yet another case of not putting the dependent shared libraries in a defined location that is supported by the program.
If you're planning on doing the 'copy the files to the same directory as the executable', the fast solution is to reference the directory in the library load path; e.g. if the binary is in $HOME/foo, you do:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}$HOME/foo
This adds or makes $HOME/foo the run-time-linker's load path. As a result, any programs you run will look in this directory for libraries, as well as the default set for the OS (defined by the ld.so configuration), as well as the paths that are defined within the application itself (the rpath).
If you're going to follow this route, what you can do is to move the binary to target.bin, create a target bash script, which invokes the bin file automatically; e.g.
#!/bin/bash -p
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}$(dirname $0)
exec $0.bin "$*"
A secondary mechanism which will permit you to change the search location for a binary; without requiring an environment variable insert is to modify the binary so that it searches in different locations than it usually does; this takes advantage of some features in the run-time linker (which looks for libraries).
There is a program called chrpath, which can be added by various package managers, which allows you to edit the rpath directly. In this case; you can change the additional search path of the binary using:
chrpath -r '$ORIGIN' foo
This means that the program will look in the same directory as the binary for .so files, thus allowing it to run.

How can i use a private installation of wxWidgets

I have two installations of wxWidgets, one in /usr/... and one private.
I don't have permissions to change the central directory.
My question is how can i make my private installation the active one?
If i only add it to the PATH setenv, it dosn't work correctly since i'm missing the LIBS.
The usual way to do something like that is to add the folder with your "private" libs to your LD_LIBRARY_PATH environment variable (assuming you're using bash and your shared libraries are in "/home/myLogin/wxWidgets/lib"),
export LD_LIBRARY_PATH="/home/myLogin/wxWidgets/lib:$LD_LIBRARY_PATH"
From The Linux Documentation Project - 3.3.1. LD_LIBRARY_PATH
You can temporarily substitute a different library for this particular execution. In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories

Shared Libraries in Same Folder with App in TCSH

I am deploying a locally-compiled app to a remote Linux server. Since I don't have root account I cannot put needed shared libraries to /usr/lib
Is there a way to overcome this? I put libraries in same folder and changed "path" variable but did not work.
Two simple options.
You can set the LD_LIBRARY_PATH variable inside your script (see Section 3.3.1. of the shared libraries HOWTO). There are problems with this approach for production code, but if set in a wrapper script is probably ok.
You can call your app with the libraries specified on the command line by invoking the ld-linux program loader directly, as described in the manpage and HOWTO:
/lib/ld-linux.so.2 --library-path PATH EXECUTABLE

Resources