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... »)
 
 
(Une révision intermédiaire par un autre utilisateur non affichée)
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:
  
<code>%BASE_LD -Wl,-rpath=/my/personal/netcdf/lib
+
<code>%BASE_LD -Wl,-rpath=/my/personal/netcdf/lib</code>
 +
 
 +
Not that '''it is generally not recommended''' to use this option as if later on the target library is moved to a different location then the executable won't work anymore... You have been warned.
 +
 
 +
05/07/2022
  
 
[[Category:HowTo]]
 
[[Category:HowTo]]

Version actuelle en date du 5 juillet 2022 à 16:03

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

Not that it is generally not recommended to use this option as if later on the target library is moved to a different location then the executable won't work anymore... You have been warned.

05/07/2022