The linker(ld) options of shared library:
-soname=name
When creating an ELF shared object, set the internal DT_SONAME field to the specified name. When an executable is linked with a shared object which has a DT_SONAME field, then when the executable is run the dynamic linker will attempt to load the shared object specified by the DT_SONAME field rather than the using the file name given to the linker.
gcc −shared −Wl,−soname,your_soname −o library_name file_list library_list
/sbin/ldconfig - configure dynamic linker run time bindings
/sbin/ldconfig [ -nNvXV ] [ -f conf ] [ -C cache ] [ -r root ] directory ...
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). 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.
/lib/ld.so run-time linker/loader
/etc/ld.so.conf File containing a list of colon, space, tab, newline, or comma-separated directories in which to search for libraries.
/etc/ld.so.cache File containing an ordered list of libraries found in the directories specified in /etc/ld.so.conf.
readelf - Displays information about ELF files
The linker(ld) uses the following search paths to locate required shared libraries:
- Any directories specified by -rpath-link options.
- Any directories specified by -rpath options. The difference between -rpath and -rpath-link is that directories specified by -rpath options are included in the executable and used at runtime, whereas the -rpath-link option is only effective at link time. It is for the native linker only.
- On an ELF system, if the -rpath and "rpath-link" options were not used, search the contents of the environment variable "LD_RUN_PATH". It is for the native linker only.
- On SunOS, if the -rpath option was not used, search any directories specified using -L options.
- For a native linker, the contents of the environment variable "LD_LIBRARY_PATH".
- For a native ELF linker, the directories in "DT_RUNPATH" or "DT_RPATH" of a shared library are searched for shared libraries needed by it. The "DT_RPATH" entries are ignored if "DT_RUNPATH" entries exist.
- The default directories, normally /lib and /usr/lib.
- For a native linker on an ELF system, if the file /etc/ld.so.conf exists, the list of directories found in that file.
The shared libraries needed by the program are searched by dynamic loader(ld-linux.so*) for in various places:
- (ELF only) Using the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist. Use of DT_RPATH is deprecated.
- Using the environment variable LD_LIBRARY_PATH. Except if the executable is a set-user-ID/set-group-ID binary, in which case it is ignored.
- (ELF only) Using the DT_RUNPATH dynamic section attribute of the binary if present.
- From the cache file /etc/ld.so.cache which contains a compiled list of candidate libraries previously found in the augmented library path. If, however, the binary was linked with -z nodeflib linker option, libraries in the default library paths are skipped.
- In the default path /lib, and then /usr/lib. If the binary was linked with -z nodeflib linker option, this step is skipped.
-( archives -)
--start-group archives --end-group
The archives should be a list of archive files. They may be either explicit file names, or -l options.
The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved.
Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives.
demo:
gcc −fPIC −g −c −Wall a.c
gcc −fPIC −g −c −Wall b.c
gcc −shared −Wl,−soname,libmystuff.so.1 −o libmystuff.so.1.0.1 a.o b.o −lc
ldconfig −n directory_with_shared_libraries
This HOWTO for programmers discusses how to create and use program libraries on Linux:
http://www.tldp.org/HOWTO/pdf/Program-Library-HOWTO.pdf