\item The advantage of static libraries is that the resulting executable file contains, before execution, everything that is necessary for it to work
\item On the other hand, a program compiled with a static library has an executable file that is much larger than the same program compiled with a dynamic library, since the definition of the library's functions is not in the executable file
\item Finally, if a static library is updated, any program that uses it will have to be recompiled so that it can take into account the modification. In the case of a dynamic library, this update does not need to be recompiled.
\item If both static and shared libraries are found, the linker gives preference to linking with the shared library unless the -static option is used.
\item To mix static and shared libraries gcc foo.c -Wl,-Bstatic -lbar -lbaz -lqux -Wl,-Bdynamic -lcorge -o foo.exe
\end{itemize}
}
...
...
@@ -91,13 +93,13 @@
When using shared librairies at runtime we need to set \cmd{LD LIBRARY PATH} so the system knows where to find the library
\begin{itemize}
\item This variable tells the program where to look for dynamic libraries; if this location is changed, it is enough to modify the variable, without changing the program
\item To tell the system to look in the directory \cmd{path/to/the/library}, the variable \cmd{LD_LIBRARY_PATH} must be initialized as follows:
\item To tell the system to look in the directory \cmd{/path/to/the/library}, the variable \cmd{LD_LIBRARY_PATH} must be initialized as follows:
\begin{consoleoutput}
$ export LD_LIBRARY_PATH=/usr/local/lib
$ export LD_LIBRARY_PATH=/path/to/the/library
\end{consoleoutput}
\item In practice, you will never define this variable but you will add files to its definition: