Search code examples
c++ubuntucompilationstatic-linkingdynamic-linking

Difference about pkg-config and LD_LIBRARY_PATH


I am trying to understand the compile and link process in C++ on Ubuntu.

From what I've learned, pkg-config is usually used to extract metadata defined in .pc file through PKG_CONFIG_PATH, then to locate the include and library file needed when compiling and linking.

My question is since we already have pkg-config, why do we bother using LD_LIBRARY_PATH and ld.so.conf? Does pkg-config and LD_LIBRARY_PATH have different use (I know LD_LIBRARY_PATH has a higher priority than ld.so.conf), or is LD_LIBRARY_PATH used for the situation when there is no .pc file, or is it just this priority thing?


Solution

  • LD_LIBRARY_PATH and ld.so.conf are used to locate shared libraries at run time, when program is started by the loader (ld.so). pkg-config files instead contain compiler/linker flags (-I, -L, -l, etc.) needed to build program that uses particular library (e.g. locate linked shlibs via -Lpath).

    Also note that many libraries lack .pc configs.