FIXME Cette page n'est pas encore traduite entièrement. Merci de terminer la traduction
(supprimez ce paragraphe une fois la traduction terminée)

Publishing links from a bookstore

Example with the library HDF5 in version 1.8.9

Static or Dynamic Linkage

In the subdirectory lib of the installation directory /softs/Hdf5/1.8.9/gnu/4.6.3, the library is available statically and dynamically. :

ls /softs/Hdf5/1.8.9/gnu/4.6.3/lib
libhdf5.a
libhdf5.so
...

Whether static or dynamic, to use this library, when editing links (compilation step), you have to add :

 -L/softs/Hdf5/1.8.9/gnu/4.6.3/lib -lhdf5 

Using the dynamic version

By default, it is the dynamic version that is first searched for when editing links. In this case, at program execution (e.g. on nodes), the variable LD_LIBRARY_PATH should contain the path of the dynamic library. To do this, add this line in the execution script :

  • For csh (and tcsh) :
setenv LD_LIBRARY_PATH "/softs/Hdf5/1.8.9/gnu/4.6.3/lib:$LD_LIBRARY_PATH"
  • For sh (and bash) :
export LD_LIBRARY_PATH="/softs/Hdf5/1.8.9/gnu/4.6.3/lib:$LD_LIBRARY_PATH"

Using the static version

To link with the static version, use the -static option. Example :

gcc ... -static ... -L/softs/Hdf5/1.8.9/gnu/4.6.3/lib -lhdf5 ...

Remarks

-static

Using the -static option implies to link all libraries statically. For only the desired library (here libhdf5) to be linked statically, use the full name of the library :

gcc ... -static ... -L/softs/Hdf5/1.8.9/gnu/4.6.3/lib/libhdf5.a ...

Availability

The above discussion arises only if both versions (static and dynamic) are installed (as for HDF5). If for another library only one of the versions (static or dynamic) is installed, just add -L/répertoire_de_recherche -lnom_librairie to link with libnom_librairie.a (or libnom_librairie.so).

en/documentation/tutorials/build/links.txt · Dernière modification: 2020/08/25 17:58 (modification externe)