Reputation: 738
I'm learning standard CMake functions, and after reading the documentation, I still have this question. They say
"Specifies the paths in which the linker should search for libraries when linking a given target"
But I don't really get how linker can look for libraries, when I use target_link_libraries()
which already knows where my libraries are.
Thank you.
Upvotes: 1
Views: 4640
Reputation: 82471
The directories you pass to this command are used you pass something that's not a cmake target to target_link_libraries
.
From the docs of target_link_libraries
This command has several signatures as detailed in subsections below. All of them have the general form
target_link_libraries(<target> ... <item>... ...)
[...]
Each
<item>
may be:
- A library target name: [...]
- A full path to a library file: [...]
- A plain library name: The generated link line will ask the linker to search for the library (e.g. foo becomes -lfoo or foo.lib). [...]
- ...
The third option ("A plain library name") is the one where target_link_directories
gets relevant; if the linker does not find the library by default, you need to add provide the path via target_link_directories
(or by similar means of modifying the LINK_DIRECTORIES
target property).
Upvotes: 1