Let's say we have freetype library already installed in /usr/lib64/libfreetype.so whose version is 1.4 and there is another version of this library that we have compiled and installed in /usr/local/lib/libfreetype.so. How does the build system (make) know which version to use when we are build a software that requires freetype?
TL;DR version: it depends.
- OS: there may be an OS specific environment (
LD_LIBRARY_PATH) configuration file or command (such as
ldconfig(8)) that registers the paths used to search for libraries.
- build system: there may be environment variables such as
LDFLAGSor command line flags or configuration file settings;
--with-curses=[dir]for when the system (or user) has ncurses under a custom path. These depend on the build system (or even then flavor of
make) and may need to be manually written into the autoconf or cmake files.
- post build configuration: tools such as
patchelf(if available) allow different libraries to be selected or the search path altered.
libxxx.so usually is a symbolic link to the shared library file that includes the version in the name.
If you link using
-lxxx, then this
libxxx.so file is used.
If you like to link against another version, you need to specify the full path name of the library.