QTP0003

Berücksichtigen Sie den Wert BUILD_SHARED_LIBS beim Erstellen von Qt-Bibliotheken.

Diese Richtlinie wurde in Qt 6.7 eingeführt. Die Richtlinie beeinflusst den Standardtyp der Bibliotheken, die mit der Qt CMake API erstellt werden, wie qt_add_library, qt_add_plugin, qt_add_qml_module.

Wenn die Richtlinie auf OLD gesetzt ist, wird der ausgewählte Standard-Bibliothekstyp an den Qt-Build-Typ angepasst, entweder shared oder static.

Wenn die Richtlinie auf NEW gesetzt ist, wird der Bibliothekstyp entsprechend dem BUILD_SHARED_LIBS-Wert ausgewählt, falls dieser gesetzt ist. Wenn BUILD_SHARED_LIBS nicht gesetzt ist, fällt der Standardbibliothekstyp auf den Qt Build-Typ zurück.

Der folgende Code verwendet zum Beispiel den Qt-Build-Typ als Standardbibliothekstyp für das Ziel MyLib, obwohl BUILD_SHARED_LIBS auf ON gesetzt ist:

set(BUILD_SHARED_LIBS ON)
...
qt6_add_library(MyLib sourcefile.h sourcefile.cpp)

Wenn Sie QTP0003 vor dem Aufruf von qt_add_library auf NEW setzen, wird BUILD_SHARED_LIBS den Standardbibliothekstyp beeinflussen und MyLib wird die gemeinsam genutzte Bibliothek sein.

set(BUILD_SHARED_LIBS ON)
...
qt_policy(SET QTP0003 NEW)
qt6_add_library(MyLib sourcefile.h sourcefile.cpp)

Siehe auch qt_policy, Qt CMake policies, und qt_add_library.

© 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.