link_directories([AFTER|BEFORE] directory1 [directory2 ...])
Adds the paths in which the linker should search for libraries. Relative paths given to this command are interpreted as relative to the current source directory, see
The directories are added to the
LINK_DIRECTORIES directory property for the current
CMakeLists.txt file, converting relative paths to absolute as needed. The command will apply only to targets created after it is called.
By default the directories specified are appended onto the current list of directories. This default behavior can be changed by setting
ON. By using
BEFORE explicitly, you can select between appending and prepending, independent of the default.
link_directories may use “generator expressions” with the syntax “$<…>”. See the
cmake-generator-expressions(7) manual for available expressions. See the
cmake-buildsystem(7) manual for more on defining buildsystem properties.
This command is rarely necessary and should be avoided where there are other choices. Prefer to pass full absolute paths to libraries where possible, since this ensures the correct library will always be linked. The
find_library() command provides the full path, which can generally be used directly in calls to
target_link_libraries(). Situations where a library search path may be needed include:
RPATHmechanisms, but some linkers are not able to fully decode those paths (e.g. due to the presence of things like
If a library search path must be provided, prefer to localize the effect where possible by using the
target_link_directories() command rather than
link_directories(). The target-specific command can also control how the search directories propagate to other dependent targets.
© 2000–2019 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.