Is /usr/local/lib searched for shared libraries?
Make sure your LD_LIBRARY_PATH
is set up to include all directories you want to search and then test it again.
You can test this quickly with:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib ffmpeg
which will set it only for that invocation.
Alternatively, you can edit /etc/ld.so.conf
which contains the default directories searched. Some Linux distributions may not include /usr/local/lib
in that file.
Note that you may also need to update the cache /etc/ld.so.cache
by running ldconfig
(as root, or with sudo
).
Shared library not found in /usr/local/lib
Figured it out. While library names have to be prefixed with "lib", that prefix must not be specified when linking. That is, gcc -o prog main.c -llibt
is wrong while gcc -o prog main.c -lt
works as expected.
How does processes find shared libraries in folders under /usr/lib
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.
Linux : error loading libraries from /usr/local/lib
Can anyone suggest what could be wrong?
If setting LD_LIBRARY_PATH
solves the problem, it's almost certain that you didn't add /usr/local/lib
to /etc/ld.so.conf.d/
correctly.
Which file in /etc/ld.so.conf.d/
did you add to?
Maybe you have a typo, or a trailing space, or something.
Shared library in /usr/local/lib not found
gcc -print-search-dirs will tell you what path the compiler checks. /usr/local/lib is simply not among them, so your compile time linker (in this case the new gold ld from binutils) doesn't find the library while the dynamic one (ld-linux.so which reads the cache written by ldconfig) does. Presumably the builds you've done previously added -L/usr/local/lib as necessary in their makefiles (usually done by a ./configure script), or you installed binaries.
Why linux doesn't search for shared libraries in the same folder
Adding . to LD_LIBRARY_PATH
is generally not recommended as it introduces security risk and also makes program behavior less predictable for the end user. If you absolutely want to go down this path and want to avoid explicit setting of LD_LIBRARY_PATH
, you can
- link with
-Wl,-rpath -Wl,'$ORIGIN'
- not call your app directly but rather through a wrapper shell script which would set proper
LD_LIBRARY_PATH
and then run the app
Cannot access local shared library from /usr/local/lib
Did you modify by yourself /etc/ld.so.conf.d/libc.conf ?
If yes, then run (as root) ldconfig to re-read the config.
gcc: linked libraries in /usr/local/lib are not found, but /etc/ld/so.conf.d/libc.conf lists it?
You should run ldconfig
(as root) after every change of the directories configured via /etc/ld.so.conf
or under /etc/ld.so.conf.d/
, in particular in your case after every update inside /usr/local/lib
(e.g. after every addition or update of some shared libraries there).
Related Topics
Limiting Memory Usage in R Under Linux
Using Grep and Sed to Find and Replace a String
How to Remove the Bom from a Utf-8 File
Optimize PDF Files (With Ghostscript or Other)
How to Perform a For-Each Loop Over All the Files Under a Specified Path
User-Data Scripts Is Not Running on My Custom Ami, But Working in Standard Amazon Linux
Syntax Error Near Unexpected Token 'Then'
Can Docker Solve a Problem of Mismatched C Shared Libraries
Compare Integer in Bash, Unary Operator Expected
Nginx: Serve Multiple Laravel Apps with Same Url But Two Different Sub Locations in Linux
Creating Executable Files in Linux
Linux Terminal Input: Reading User Input from Terminal Truncating Lines at 4095 Character Limit
How to Run Nginx Within a Docker Container Without Halting
Colour Highlighting Output Based on Regex in Shell