Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CMake's find_library search LD_LIBRARY_PATH?

Tags:

cmake

Despite reading the documentation I can't figure out whether CMake's command find_library searches or not the directories listed in LD_LIBRARY_PATH.

My tests give mixed results.

like image 828
Barth Avatar asked Dec 12 '25 00:12

Barth


2 Answers

From the documentation (I didn't reproduced the text related to cmake variables nor parameters of find_library, which are not relevant here):

If NO_DEFAULT_PATH is specified, then no additional paths are added to the search. If NO_DEFAULT_PATH is not specified, the search process is as follows:

...

  1. Search the standard system environment variables. This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
    • Directories in LIB. On Windows hosts: <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/lib for each <prefix>/[s]bin in PATH, and <entry>/lib for other entries in PATH, and the directories in PATH itself.

...

So LD_LIBRARY_PATH is not used by find_library. This is confirmed reading the source code.

The mixed results of your tests may come from an other variable, but without a detailed description of these tests, this is just a guess.

like image 91
rgmt Avatar answered Dec 14 '25 12:12

rgmt


According to the current documentation and a small test, it seems that LD_LIBRARY_PATH is not considered.


The documentation for find_library says

If NO_DEFAULT_PATH is specified, then no additional paths are added to the search. If NO_DEFAULT_PATH is not specified, the search process is as follows:

  1. Search paths specified in cmake-specific cache variables. These are intended to be used on the command line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is passed.
    • <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/lib for each <prefix> in CMAKE_PREFIX_PATH
    • CMAKE_LIBRARY_PATH
    • CMAKE_FRAMEWORK_PATH
  2. Search paths specified in cmake-specific environment variables. These are intended to be set in the user’s shell configuration. This can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.
    • <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/lib for each <prefix> in CMAKE_PREFIX_PATH
    • CMAKE_LIBRARY_PATH
    • CMAKE_FRAMEWORK_PATH
  3. Search the paths specified by the HINTS option. These should be paths computed by system introspection, such as a hint provided by the location of another item already found. Hard-coded guesses should be specified with the PATHS option.
  4. Search the standard system environment variables. This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
    • Directories in LIB, <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/lib for each <prefix>/[s]bin in PATH, and <entry>/lib for other entries in PATH, and the directories in PATH itself.
  5. Search cmake variables defined in the Platform files for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is passed.
    • <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and <prefix>/lib for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
    • CMAKE_SYSTEM_LIBRARY_PATH
    • CMAKE_SYSTEM_FRAMEWORK_PATH
  6. Search the paths specified by the PATHS option or in the short-hand version of the command. These are typically hard-coded guesses.

Since CMAKE_PREFIX_PATH and CMAKE_LIBRARY_PATH are specified to be empty (by default), the question is equivalent to the following: Is LD_LIBRARY_PATH considered by CMAKE_SYSTEM_PREFIX_PATH or CMAKE_SYSTEM_LIBRARY_PATH. According to a simple test I made with CMake 3.7.1, LD_LIBRARY_PATH is not considered by them.

like image 31
JojOatXGME Avatar answered Dec 14 '25 12:12

JojOatXGME