unixpathcmakelinker

How is $PATH used outside of the shell?


I was recently asked why a particular library (Accelerate) is not included in the $PATH variable in our Mac environment. My response to that is that $PATH is a shell concept, not an OS concept. I don't expect libraries to be included in $PATH since they aren't executable and aren't necessarily relevant in a shell.

However, is this true? Some googling says yes, but in that case how do tools like CMake automatically find libraries with find_package and find_lapack? Is there some system specific PATH variable or another similar concept?


Solution

  • Yes, the PATH environment variable is for storing paths to executable files. There is to my knowledge (nor did an internet search reveal one) no standard PATH equivalent for library locations.

    Tools like CMake will typically search the standard locations. For a Unix flavored OS, these often include /usr/lib, /usr/local/lib etc. See for example how CMake defines them: UnixPaths.cmake.

    find_library() will search these standard locations (unless you tell it not to), and/or any path(s) given by the user.

    find_package() will search for a Config or Find-module, which is responsible for finding all the necessary package components (binaries, include folders etc) and make the package ready for use within CMake. As these are written for a specific package, they will typically employ some qualified "guess work" as to where to find the package and its components (search standard locations, typical install locations and/or any other arbitrary method to accomplish its mission). So it's not CMake itself that finds the package in this case.