WhatIs: The LD LIBRARY PATH environment variable : Différence entre versions

De LMDZPedia
Aller à : navigation, rechercher
(Page créée avec « When a program runs, it looks for the dynamically linked libraries (*.so files) it needs. The information on where to look for is stored in the LD_LIBRARY_PATH environmen... »)
 
 
(Une révision intermédiaire par le même utilisateur non affichée)
Ligne 9 : Ligne 9 :
 
<code>error while loading shared libraries: libnetcdff.so</code>
 
<code>error while loading shared libraries: libnetcdff.so</code>
  
In the example above <ode>libnetcdf.so</code> was not found in any of the directories listed in LD_LIBRARY_PATH. Simply updating LD_LIBRARY_PATH with the correct path (for the sake of this example let's say libnetcdff.so is located in /my/personal/libraries/netcdf/lib):
+
In the example above <code>libnetcdf.so</code> was not found in any of the directories listed in LD_LIBRARY_PATH. Simply updating LD_LIBRARY_PATH with the correct path (for the sake of this example let's say libnetcdff.so is located in /my/personal/libraries/netcdf/lib):
  
 
<code>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my/personal/libraries/netcdf/lib</code>
 
<code>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my/personal/libraries/netcdf/lib</code>
Ligne 20 : Ligne 20 :
  
 
Note that an alternative to having to specify the paths in LD_LIBRARY_PATH is to specify the path at compile time (at the linking step) using the <code>-Wl,-rpath=</code> option
 
Note that an alternative to having to specify the paths in LD_LIBRARY_PATH is to specify the path at compile time (at the linking step) using the <code>-Wl,-rpath=</code> option
 +
 +
27/09/2021
  
 
[[Category:WhatIs]]
 
[[Category:WhatIs]]

Version actuelle en date du 27 septembre 2021 à 11:17

When a program runs, it looks for the dynamically linked libraries (*.so files) it needs.

The information on where to look for is stored in the LD_LIBRARY_PATH environment variable, which contains the list of paths to scan, e.g.:

LD_LIBRARY_PATH=/some/path/to/lib:/some/other/path/to/lib

If the program fails to find a sought library, then it will not start and stop with an error message of the likes of:

error while loading shared libraries: libnetcdff.so

In the example above libnetcdf.so was not found in any of the directories listed in LD_LIBRARY_PATH. Simply updating LD_LIBRARY_PATH with the correct path (for the sake of this example let's say libnetcdff.so is located in /my/personal/libraries/netcdf/lib):

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my/personal/libraries/netcdf/lib

will solve the problem. Note that you have to first update the LD_LIBRARY_PATH environment variable and the run your program.

To know which *.so libraries an executable (e.g. mycode.e) needs and where it finds them:

ldd mycode.e

Note that an alternative to having to specify the paths in LD_LIBRARY_PATH is to specify the path at compile time (at the linking step) using the -Wl,-rpath= option

27/09/2021