Using Ldconfig on Linux

Using ldconfig on Linux

ldconfig looks inside all shared objects that it finds, to look for the soname. It then creates a link using that soname as the name of the link. It's conventional (but far from universally done) for the soname to be the name and major version of the library, so your library foo.so.1.1 will have a soname of foo.so.1 and ldconfig will make a link called that.

No part of the run-time system looks for or knows anything about the name foo.so. That's used when you link your programs to the library. There's no point in having that link unless you also have all the other development files (headers etc) for the library, so there's no point in ldconfig automatically creating it. And since the name of the link to use is only another convention, and in this case isn't stored inside the file at all, there's no way for ldconfig to know what name to create.

Normally this would be created manually, in the install target of the Makefile; when a library is packaged for a linux distribution the link normally lives in the -dev package along with the header files.

Proper use of LD_LIBRARY_PATH or ldconfig for a software package

In case anyone else finds this useful, I ended up doing this before building:

export LD_RUN_PATH='$ORIGIN/../lib'

This includes a library path in the binary itself, relative to the location of the binary. If you plan to use this in a bash script or in your build files, make sure to look up your particular usage with $ORIGIN since there are cases when you need to do something like \$$ORIGIN, \$$ORIGIN or $$ORIGIN so that different utilities involved in the build get the dollar sign escaped properly. Finding this useful bit saved me having to update about 50 individual scripts that run as a batch to build our software pack.

ldconfig loading only .so files

Found the answer here. The Solution was simple: make a copy that matches the pattern.

cp /usr/local/lib/libdnet.1.0.1 /usr/local/lib/libdnet.so.1.0.1

A less preferred alternative:

$ LD_LIBRARY_PATH=/usr/local/lib
$ export LD_LIBRARY_PATH

ldconfig register .so lib

Answer is here: https://codeyarns.com/2017/11/02/how-shared-library-locations-are-found-at-runtime/

I added my *.so libs into /lib/ directory.

ld.so.conf does not get loaded by ldconfig

You have to add library or directory itself:

/full/Path/to/library.so/or/directory to /etc/ld.so.conf file

You must remove include word before directory in your config file.

From man ldconfig:

The ldconfig utility is used to prepare a set of ``hints'' for use
by the
dynamic linker to facilitate quick lookup of shared libraries available
in multiple directories.

<...>

Files named on the command line are expected to contain directories to
scan for shared libraries. Each directory's pathname must start on a new
line. Blank lines and lines starting with the comment character `#' are
ignored. Filenames must conform to the lib*.so.[0-9] pattern in order to
be added to the hints file.



Related Topics



Leave a reply



Submit