HowTo: Hard code the path to a dynamic library in the executable : Différence entre versions

De LMDZPedia
Aller à : navigation, rechercher
(Page créée avec « If you don't want to use the LD_LIBRARY_PATH environment variable (this is however the recommended way to proceed) to let your executable know where to find needed dynamic... »)
 
Ligne 11 : Ligne 11 :
  
 
== LMDZ-specific example ==
 
== LMDZ-specific example ==
Since compilation options are set in the arch.fcm file, this is where the option  <code>-Wl,rpath=...</code> should be set, on the line starting with <code>%BASE_LD</code>
+
Since compilation options are set in the [[WhatIs:_The_target_architecture_("arch")_files|arch.fcm]] file, this is where the option  <code>-Wl,rpath=...</code> should be set, on the line starting with <code>%BASE_LD</code>
  
 
For example if one wants to hard code to look for personal netcdf libraries that are located in /my/personal/netcdf/lib:
 
For example if one wants to hard code to look for personal netcdf libraries that are located in /my/personal/netcdf/lib:

Version du 27 septembre 2021 à 11:22

If you don't want to use the LD_LIBRARY_PATH environment variable (this is however the recommended way to proceed) to let your executable know where to find needed dynamic libraries (*.so shared object libraries), you can hard code the paths at compile (linking) time, with the -Wl,rpath= option.

general illustrative example

You want your executable to always first look for the needed library in /my/personal/stuff/lib and /some/other/place/lib , then compile with:

-Wl,rpath=/my/personal/stuff/lib:/some/other/place/lib

The drawback of this method is that if the libraries are later moved to different locations, your executable won't know about it and probably abort with an error message of the likes of:

error while loading shared libraries: ...

LMDZ-specific example

Since compilation options are set in the arch.fcm file, this is where the option -Wl,rpath=... should be set, on the line starting with %BASE_LD

For example if one wants to hard code to look for personal netcdf libraries that are located in /my/personal/netcdf/lib:

%BASE_LD -Wl,-rpath=/my/personal/netcdf/lib