You need to use ldconfig config file and ldconfig command which creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories such as /lib64 or /usr/lib64 (/lib or /usr/lib on 32 bit systems).
Tutorial details | |
---|---|
Difficulty | Intermediate (rss) |
Root privileges | Yes |
Requirements | GNU gcc |
Time | 10m |
Add Your Path
Create a file called /etc/ld.so.conf.d/myapp.conf:
# vi /etc/ld.so.conf.d/myapp.conf
Add the following path:
/usr/local/lib
Save and close the file.
Activate Your Library Path
You must run the following command to activate path:
# ldconfig
Verify Your New Library Path
# ldconfig -v | less
OR
# ldconfig -v | grep /usr/local/lib
Sample outputs:
/usr/local/lib: libGeoIP.so.1 -> libGeoIP.so.1.4.6 libGeoIPUpdate.so.0 -> libGeoIPUpdate.so.0.0.0 /usr/lib64/mysql: libmysqlclient_r.so.15 -> libmysqlclient_r.so.15.0.0 libmysqlclient.so.15 -> libmysqlclient.so.15.0.0 /lib: libutil.so.1 -> libutil-2.5.so
How Do I Delete The Library Path?
Simply, delete the file:
# rm /etc/ld.so.conf.d/myapp.conf
# ldconfig
How Do I Edit The Library Path?
Simply edit the file and reload the changes:
# vi /etc/ld.so.conf.d/myapp.conf
# ldconfig
How Do I Compile Program With Shared Libs And GNU GCC?
You can use the following gcc
$ gcc -Wl,-R/path/to/lib -I/path/to/include -L/path/to/lib -o myAppName mycode.c -llibapp2
See gcc man page for further details.
Further readings:
- Linux Commands For Shared Library Management & Debugging Problem
- See the following man pages for more information:
man ldconfig
man ld
man gcc
🐧 5 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Great article.
Unfortunately in Fedora 12 the (local) manual page of ldconfig is missing :-(
You don’t cease to amaze me Vivek. Great article to keep my Linux journey going.
Great information…
Thanks a lot.
Old thread but still, I’ll try.
Can’t we just add any path to LD_LIBRARY_PATH environment variable ?
(I’m working on a system on which I don’t have root privileges…)
You are my hero