Linux ldconfig symbolic link

3 UNIX / Linux ldconfig Command Examples

This displays the list of directories and the libraries that are stored in the current cache. In the following example, it indicates that there are 916 libraries found in the cache file /etc/ld.so.cache, and it lists all of them below.

# ldconfig -p | head -5 916 libs found in cache `/etc/ld.so.cache' libzephyr.so.4 (libc6) => /usr/lib/libzephyr.so.4 libzbar.so.0 (libc6) => /usr/lib/libzbar.so.0 libz.so.1 (libc6) => /lib/libz.so.1 libz.so (libc6) => /usr/lib/libz.so

2. Display libraries from every directory

Scans all the directories, and prints the directory name, and all the links that are created under it.

# ldconfig -v | head /usr/lib/mesa: libGL.so.1 -> libGL.so.1.2 /usr/lib/i686-linux-gnu: liblouis.so.2 -> liblouis.so.2.2.0 /usr/lib/alsa-lib: libasound_module_ctl_oss.so -> libasound_module_ctl_oss.so libasound_module_ctl_bluetooth.so -> libasound_module_ctl_bluetooth.so libasound_module_pcm_bluetooth.so -> libasound_module_pcm_bluetooth.so libasound_module_pcm_vdownmix.so -> libasound_module_pcm_vdownmix.so libasound_module_rate_speexrate.so -> libasound_module_rate_speexrate_medium.so

The /etc/ld.so.conf has an include statement, which indicates that all the *.conf file under /etc/ld.so.conf.d directory should be considered.

# cat /etc/ld.so.conf include /etc/ld.so.conf.d/*.conf

As you see below, there are multiple *.conf file located under this ld.so.conf.d directory. All of these files will be used.

# ls -1 /etc/ld.so.conf.d/ GL.conf i486-linux-gnu.conf i686-linux-gnu.conf libasound2.conf libc.conf

Sometimes when you do ldconfig -v, you might get the following error. This is because the directory referred by some of the *.conf file located under /etc/ld.so.conf.d is not valid, and contains directory names that doesn’t exist.

/sbin/ldconfig.real: Can't stat /lib/i486-linux-gnu: No such file or directory /sbin/ldconfig.real: Can't stat /usr/lib/i486-linux-gnu: No such file or directory /sbin/ldconfig.real: Can't stat /lib/i686-linux-gnu: No such file or directory /sbin/ldconfig.real: Can't stat /lib64: No such file or directory

Note: You can either ignore these error mesages are remove those *.conf files from the /etc/ld.so.conf.d directory.

3. Inform System about the New Libraries

If you’ve installed a new program by compiling it from source, you might want to inform the system about the new libraries. For example, let us assume that you’ve installed a program called dummy, which has all it’s libraries under /opt/dummy/lib directory. The following example will update the links using only the directory /opt/dummy/lib. This doesn’t rebuilt the links by processing the /etc/ld.so.conf file. Please note that this doesn’t rebuild the cache. It just updates the link.

Syntax and Options

Short Option Long Option Option Description
-v –verbose Indicates verbose mode. Prints current version number, name of each directory as it is scanned and links that are created.
-n Process the directories that are specified from the command line. This doesn’t process the regular /usr/lib and lib directories. This also doesn’t process directories specified in the /etc/ld.so.conf. This option implies -N.
-N This doesn’t rebuild the cache. Unless -X is also specified, links are still updated.
-X This doesn’t update the links. Unless -N is also specified, the cache is still rebuilt.
-f Use the specified config file instead of /etc/ld.so.conf.
-C Use the specified cache instead of /etc/ld.so.cache.
-r Change to and use root as the root directory.
-l This is library mode, which manually links individual libraries.
-p –print-cache Print the lists of directories and candidate libraries stored in the current cache.
-c FORMAT –format=FORMAT Uses FORMAT for the cache file. Valid values for FORMAT: old, new and compat. compat is the default value.
-i –ignore-aux-cache Ignore auxiliary cache file.
-? –help, –usage Display help
-V –version Display version number
Читайте также:  Read block device linux

Thanks for the tutorial. I did the following kesten@kesten-K42Jr:~/vcp/SVN/Sofa-1.0/lib/linux$ ldconfig -l /media/DATA/VersionControlProjects/SVN/Sofa-1.0/lib/linux/*.* and recieved this error message.
/sbin/ldconfig.real: Ignored file /media/DATA/VersionControlProjects/SVN/Sofa-1.0/lib/linux/libtinyxml.so since it is not a regular file. vcp is a symbolic link from my linux drive to my /media/DATA drive.
What is a regular file and why are these “not regular” files being ignored? kesten

One critical piece of information was left out of this article thus rendering it useless to anyone who doesn’t already know the info. What goes in the *.conf files under the /etc/ld.so.conf/d/ directory?

@Steve: One line, containing the path to the folder you want to include in search for the matching .so.

Источник

DESCRIPTION

ldconfig 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, /lib and /usr/lib. On some 64-bit architectures such as x86-64, /lib and /usr/lib are the trusted directories for 32-bit libraries, while /lib64 and /usr/lib64 are used for 64-bit libraries.

The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated. ldconfig should normally be run by the superuser as it may require write permission on some root owned directories and files.

ldconfig will look only at files that are named lib*.so* (for regular shared objects) or ld-*.so* (for the dynamic loader itself). Other files will be ignored. Also, ldconfig expects a certain pattern to how the symbolic links are set up, like this example, where the middle file (libfoo.so.1 here) is the SONAME for the library:

libfoo.so -> libfoo.so.1 -> libfoo.so.1.12

Failure to follow this pattern may result in compatibility issues after an upgrade.

OPTIONS

-c fmt -C cache Use cache instead of /etc/ld.so.cache. -f conf Use conf instead of /etc/ld.so.conf. -i —ignore-aux-cache (Since glibc 2.7) Ignore auxiliary cache file. -l (Since glibc 2.2) Interpret each operand as a library name and configure its links. Intended for use only by experts. -n Process only the directories specified on the command line; don’t process the trusted directories, nor those specified in /etc/ld.so.conf. Implies -N. -N Don’t rebuild the cache. Unless -X is also specified, links are still updated. -p —print-cache Print the lists of directories and candidate libraries stored in the current cache. -r root Change to and use root as the root directory. -v —verbose Verbose mode. Print current version number, the name of each directory as it is scanned, and any links that are created. Overrides quiet mode. -V —version Print program version. -X Don’t update links. Unless -N is also specified, the cache is still rebuilt.

Читайте также:  Поднять dns сервер linux

FILES

/lib/ld.so is the run-time linker/loader. /etc/ld.so.conf contains a list of directories, one per line, in which to search for libraries. /etc/ld.so.cache contains an ordered list of libraries found in the directories specified in /etc/ld.so.conf, as well as those found in the trusted directories.

SEE ALSO

Package name: core/man-pages Version: 6.04-1 Upstream: https://www.kernel.org/doc/man-pages/ Licenses: GPL, custom Manuals: /listing/core/man-pages/ Table of contents

Powered by archmanweb, using mandoc for the conversion of manual pages.

The website is available under the terms of the GPL-3.0 license, except for the contents of the manual pages, which have their own license specified in the corresponding Arch Linux package.

Источник

Linux ldconfig Command With Examples

The Linux ldconfig command creates, updates, and removes available symbolic links for currently shared libraries. The symbolic links are based on lib directories in /etc/ld.so.conf. Linux commands rely on shared libraries. Multiple commands and executables often share libraries, implying that each can use the library without affecting the other.

These shared libraries require means of managing them. It’s the work of the ldconfig to create the needed links and cache useful to manage shared libraries. Let’s see how to use the ldconfig command.

How To Use the ldconfig Command

The ldconfig checks the file names and the header for different libraries to determine which has the most updated links when updating link files.

Furthermore, it creates the file, /etc/ld.so.cache, helpful in speeding up the linking of libraries by the run-time linker.

The configuration file containing shared libraries used by ldconfig is located at /etc/ld.so.conf. The configuration file dictates the ldconfig to use all the configuration files in the specified directory. If you open the file, it contains one line.

1. Using ldconfig To Show Libraries From the Cache

The ldconfig can display all the currently located files in the cache. It shows the entire library and lists its location on the command line.

Читайте также:  Linux public key file

We are adding “head” to reduce the output of the libraries by printing the first five lines.

2. Show All Libraries

You can display every library in every directory using the “-v” option. The command goes through each directory in the system, printing the directory’s name and the corresponding links created under it.

However, some directories listed under the /etc/ ld.so.conf don’t exist. You may notice some error messages in the output.

3. Adding New Libraries

When a new program gets installed by compiling it from the source, you must inform the system about this new library. There are two ways to go about it.

The first is to use the ldconfig command using the “-n” option and directly update the links using the new library only. However, this method doesn’t build the cache. It only updates the link to the new library. For instance, if you’ve installed a program like veil in the /opt directory, using the following command will directly update the library’s link:

Alternatively, you can use an editor, like vi, and add the /veil/lib to the /etc/ld.so.conf to execute the ldconfig to update all links.

The command below will open the configuration file where you get to add the /opt/veil/lib. Note that veil is our example program. Replace it with the one you need to add in your case.

To update the cache, run the following command as root:

You can verify that the library was added by running the “-v” option and grep the library’s name. For instance, we can check if the libFLAC library is available using the following command:

If it’s present, it should return an output similar to the one below:

ldconfig has other commands, and you can access them from its man page. However, the ones we’ve listed using the previous examples are what you need to know when working with libraries and programs.

ldconfig helps deal with shared libraries. In addition, it’s also possible to see the shared libraries used by a given command. You can use the “ldd” command followed by the program—for instance, a program like echo.

Conclusion

The ldconfig uses the contents of the /etc/ld.so.conf file to create symbolic links and a cache, /etc/ls.so.cache. This is read by programs, especially executable and shared programs. This guide covered the different files that ldconfig worked with and showed examples of using the ldconfig Linux command to display and add libraries.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.

Источник

Оцените статью
Adblock
detector