top of page
  • dlinluaduzofin

How To Check Ld Library Path In Solaris



If your library path error is in the linker, during compile, you need to add the path to the library into the variable $LD_LIBRARY_PATH. If the library error is when you actually run the compiled program then you need to add the library path to /etc/ld.so.conf and run ldconfig to rebuild the library search path cache.


The purpose of the LD_LIBRARY_PATH environment variable is to instruct thelinker to consider additional directories when searching for libraries. Itsvalid use case is the test of alternative library versions installed innon-standard locations. In contrast to that, globally setting theLD_LIBRARY_PATH (e.g. in the profile of a user) is harmful because there isno setting that fits every program. The directories in the LD_LIBRARY_PATHenvironment variable are considered before the default ones and the onesspecified in the binary executable. Thus, a - say - systemcommand that is supposed to use a system library easily gets linked at runtimewith an API incompatible version. Also, having a program that relies on acertain LD_LIBRARY_PATH setting creates the maintenance burden to alwaysaccurately document that setting and distribute that documentation with thebinary. Instead, to avoid these issues, the additional directories (if any)that should be searched by the runtime linker should be specified via linkeroptions (e.g. -rpath or -R) at build-time. This results in thosedirectories being written to an ELF attribute that is considered by the runtimelinker (i.e. the runpath).




how to check ld library path in solaris



The LD_LIBRARY_PATH directories aren't considered when ld searches forlibraries specified via -l. But, the LD_LIBRARY_PATH is considered whenshared library dependencies of linked shared libraries are resolved (cf.-rpath-link in ld(1)). In that case, the LD_LIBRARY_PATH directoriesare searched after the ones specified with -rpath-link and -rpath butbefore ones specified by ELF attributes and the default ones (e.g. /lib and /usr/lib).


Analogously to the -LSOMEDIR option that adds a directory to the build-timelibrary search path, the option -Wl,-rpath,SOMEDIR (or -Wl,-RSOMEDIR) adds adirectory to the runtime library search path. That means that theresulting path is written by the linker into the DT_RPATHand/or DT_RUNPATH ELF attribute of the resulting binary.


Other interesting attributes dumped by those tools and that are relevant inthis context are NEEDED (i.e. the dependent shared libraries specified via-l or as absolute path) and SONAME (i.e. the name of a shared librarythat is copied from the library to the NEEDED attribute of the binary thatdepends on that library).


The linker searches for librariesat several locations and in a certain prescribed order. Some of these locationsare standard paths, while others depend on the compiler options -Rpath, -llibrary,and -Ldir and the environmentvariable LD_LIBRARY_PATH.


The standard library search paths used by the linker are determinedby the installation path, and they differ for static and dynamic loading.A standard install puts the Sun Studio compiler software under /opt/SUNWspro/.


The linker looks in the standard directory paths to find the additional libmylib library. The -L option (and the LD_LIBRARY_PATH environment variable) creates a list of pathsthat tell the linker where to look for libraries outside the standard paths.


When building the executable file, the linker recordsthe paths to shared libraries in the executable itself. These search pathscan be specified using the -Rpath option.This is in contrast to the -Ldir optionwhich indicates at buildtime where to find the library specified by a -llibrary option, but does not recordthis path into the binary executable.


Libraries are linked either statically or dynamically(also called shared libraries). Libraries live in/usr/lib amongst other places. Static libraries (.asuffix) are incorporated into the binary at link time, whereas dynamicones (.so suffix) are referenced by location. There is a movein Solaris and less so in UNIX in general to using dynamic librarieswherever possible (Solaris ships with less static libraries at eachrelease). Once a library has been linked with statically, if the sameversion of the library is updated (eg. minor upgrade, bug fix) thebinary would need to be manually relinked to use the newlibrary. Other tricks with dynamic libraries are possible, such asusing a per-architecture copy of the library optimised for theprocessor/architecture on the current host.Specifying the location of dynamic libraries not in /usr/libIn UNIX the location of a library can be specified with the-L dir option to the compiler. Furthermore, in Solarisyou need to specify the run time location with a corresponding-R dir option. For example, suppose we need to use thefreely available libz in our C program, squash,built from squash.c. This is not part of Solaris so it isinstalled in /usr/local/lib. Here's a typical command tobuild it with Sun's C compiler - cc(1):$ cc -o squash -L/usr/local/lib -R/usr/local/lib -lz squash.cWe could check what dynamic libraries are used with ldd(1)(list dynamic dependencies):


For the following reasons:LD_LIBRARY_PATH is used in preference to any run time ordefault system linker path. If (God forbid) you had it set tosomething like /dcs/spod/baduser/lib, if there was a hackedversion of libc in that directory (for example) your accountcould be compromised. It is for this reason that set-uid programscompletely ignore LD_LIBRARY_PATH.When code is compiled and depends on this to work, it can causeconfusion where different versions of a library are installed indifferent directories, for example there is a libtiff in/usr/openwin/lib and /usr/local/lib. In this case,the former library is an older one used by some programs that comewith Solaris.Sometimes when using precompiled binaries they may have been builtwith 3rd party libraries in specific locations; ideally code shouldeither ship with the libraries and install into a certain location orlink the code as a pre-installation step. Solaris 7 introduces$ORIGIN which allows for a relative library locationto be specified at run time (see the Solaris Linkerand Libraries Guide). The alternative is to setLD_LIBRARY_PATH on a per-program basis, either as a wrapperprogram to the real program or a shell alias. Note however, thatLD_LIBRARY_PATH may be inherited by programs called by thewrapped one ...Further informationThe Solaris Linkerand Libraries Guide


Next you need to know what identifier your OS uses to define the library path (example: Solaris, Linux: LD_LIBRARY_PATH, HP: SHLIB_PATH, AIX: LIBPATH) Then set the following variables using the appropriate location for AutoSys and library path designation for your OS as in this example for Solaris:


This install problem is occurring because a library is missing in the Solaris SPARC Path. 1. Find the library that is missing. Do a find / -name "libggc*" -print example at the bottom. The library that you need to find is libgcc_s.so.1Notes: On some Solaris Sparc Systems this library (libgcc_s.so.1) is not in the ld library path. Under most Solaris x86 systems it is there. 2. Add the library (libgcc_s.so.1) to the LD_LIBRARY_PATH. Example: LD_LIBRARY_PATH=/lib:/usr/lib:/usr/sfw/lib Note: The method used to add this to the path will vary depending on which shell you are running.Another Option:If the library can not be found using the process above, copy the entire VOP directory from the x86 version to the Sparc version using the process below.Process:# find . -name "libgcc*" -print./usr/lib/AdobeReader/Adobe/Reader8/Reader/sparcsolaris/lib/libgcc_s.so./usr/lib/AdobeReader/Adobe/Reader8/Reader/sparcsolaris/lib/libgcc_s.so.1./usr/sfw/lib/sparcv9/libgcc_s_sparcv9.so./usr/sfw/lib/sparcv9/libgcc_s.so.1./usr/sfw/lib/libgcc_s.so./usr/sfw/lib/libgcc_s.so.1./usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/sparcv9/libgcc.a./usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/sparcv9/libgcc_eh.a./usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/libgcc.a./usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/libgcc_eh.a./usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/libgcc.a./usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/libgcc_eh.a./usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/sparcv9/libgcc.a./usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/sparcv9/libgcc_eh.a./usr/local/lib/libgcc_s.so./usr/local/lib/libgcc_s.so.1./usr/local/lib/sparcv9/libgcc_s.so.1./usr/local/lib/sparcv9/libgcc_s_sparcv9.so./main/10_Recommended/patches/121104-11/SUNWacroread/reloc/lib/AdobeReader/Adobe/Reader8/Reader/sparcsolaris/lib/libgcc_s.so.1Type: set LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/usr/sfw/libNote: The above syntax may change if in CSH or BASH.


Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library). This RPATH header value (so named in the Executable and Linkable Format header standards) may either override or supplement the system default dynamic linking search paths.


The rpath of an executable or shared library is an optional entry in the .dynamic section of the ELF executable or shared libraries, with the type DT_RPATH, called the DT_RPATH attribute. It can be stored there at link time by the linker. Tools such as chrpath and patchelf can create or modify the entry later.


If the new-dtags feature is enabled in the linker (--enable-new-dtags), GNU ld, besides setting the DT_RPATH attribute, also sets the DT_RUNPATH attribute to the same string. At run time, if the dynamic linker finds a DT_RUNPATH attribute, it ignores the value of the DT_RPATH attribute, with the effect that LD_LIBRARY_PATH is checked first and the paths in the DT_RUNPATH attribute are only searched afterwards. 2ff7e9595c


1 view0 comments

Recent Posts

See All
bottom of page