QTP0003
创建 Qt 库时考虑 BUILD_SHARED_LIBS 值。
该策略在 Qt 6.7 中引入。该策略会影响使用Qt CMake API 创建的库的默认类型,如qt_add_library、qt_ add_plugin、qt_add_qml_module。
如果策略设置为OLD
,则选择的默认库类型与 Qt 构建类型一致,即shared
或static
。
如果策略设置为NEW
,则根据BUILD_SHARED_LIBS值(如果已设置)选择库类型。如果BUILD_SHARED_LIBS
未设置,默认库类型会退回到 Qt 构建类型。
例如,下面的代码将使用 Qt 构建类型作为MyLib
目标的默认库类型,尽管BUILD_SHARED_LIBS
已设置为ON
:
set(BUILD_SHARED_LIBS ON) ... qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
如果在调用qt_add_library之前将 QTP0003 设置为NEW
,那么BUILD_SHARED_LIBS
将影响库的默认类型,而MyLib
将成为共享库。
set(BUILD_SHARED_LIBS ON) ... qt_policy(SET QTP0003 NEW) qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.