QTP0003
Berücksichtigen Sie den Wert von BUILD_SHARED_LIBS beim Erstellen von Qt-Bibliotheken.
Diese Richtlinie wurde in Qt 6.7 eingeführt. Die Richtlinie wirkt sich auf den Standardtyp der Bibliotheken aus, die mithilfe der Qt-CMake-API erstellt werden, wie z. B. qt_add_library(), qt_add_plugin() und qt_add_qml_module().
Wenn die Richtlinie auf „ OLD “ gesetzt ist, richtet sich der ausgewählte Standardbibliotheks-Typ nach dem Qt-Build-Typ, also entweder „ shared “ oder „ static “.
Ist die Richtlinie auf „ NEW “ gesetzt, wird der Bibliothekstyp entsprechend dem Wert von „BUILD_SHARED_LIBS“ ausgewählt, sofern dieser festgelegt ist. Ist „ BUILD_SHARED_LIBS “ nicht festgelegt, greift der Standardbibliothekstyp auf den Qt-Build-Typ zurück.
Beispielsweise verwendet der folgende Code den Qt-Build-Typ als Standard-Bibliotheks-Typ für das Ziel „ MyLib “, obwohl „ BUILD_SHARED_LIBS “ auf „ ON “ gesetzt ist:
set(BUILD_SHARED_LIBS ON)
...
qt_add_library(MyLib sourcefile.h sourcefile.cpp)Wenn Sie QTP0003 vor dem Aufruf von `qt_add_library()` auf „ NEW “ setzen, wirkt sich „ BUILD_SHARED_LIBS “ auf den Standardtyp der Bibliothek aus, und „ MyLib “ wird zur gemeinsam genutzten Bibliothek.
set(BUILD_SHARED_LIBS ON)
...
qt_policy(SET QTP0003 NEW)
qt_add_library(MyLib sourcefile.h sourcefile.cpp)Siehe auch qt_policy(), Qt-CMake-Richtlinien und qt_add_library().
© 2026 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.