CMake中”link_libraries”和”target_link_libraries”的区别. The difference between “link_libraries” and “target_link_libraries”.

官方文档:
link_libraries — CMake 3.23.2 Documentation;
target_link_libraries — CMake 3.23.2 Documentation.

官方文档中这么说:

link_libraries

Link libraries to all targets added later.
link_libraries([item1 [item2 […]]] [[debug|optimized|general] <item>] …)
Specify libraries or flags to use when linking any targets created later in the current directory or below by commands such as add_executable() or add_library(). See the target_link_libraries() command for meaning of arguments.
Note
 The target_link_libraries() command should be preferred whenever possible. Library dependencies are chained automatically, so directory-wide specification of link libraries is rarely needed.
翻译:
link_libraries
所有稍后添加的目标的链接库.
link_libraries([item1 [item2 […]]] [[debug|optimized|general] <item>] …) (这是用法)
指定库或标志,以便在通过add_executable()或add_library()等命令链接稍后在当前目录或以下目录中创建的任何目标时使用. 有关参数的含义,请参阅target_link_libraries()命令.
批注:
尽可能首选target_link_libraries()命令. 库依赖项是自动链接的, 因此很少需要指定链接库的目录范围.

target_link_libraries

Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target’s dependencies affect compilation of its own sources.
This command has several signatures as detailed in subsections below. All of them have the general form
target_link_libraries(<target> … <item>… …)
The named <target> must have been created by a command such as add_executable() or add_library() and must not be an ALIAS target. If policy CMP0079 is not set to NEW then the target must have been created in the current directory. Repeated calls for the same <target> append items in the order called.

编写中…

 Save as PDF
最后修改日期: 2022-06-04

作者

留言

撰写回覆或留言