Linking static vs shared libraries (Qt 6 CMake)
Unsolved
General and Desktop
-
wrote on 24 Nov 2022, 19:37 last edited by
Could someone explain the following please.
If I create a SHARED library as follows...
qt_add_library(NovaLib SHARED) qt_add_qml_module(NovaLib URI Nova ...) qt_add_executable(app main.cpp) qt_add_qml(app URI MyApp VERSION 1.0 QML_FILES main.qml)
then I need to link to the library itself
target_link_libraries(app PRIVATE ... NovaLib)
But if I create a STATIC library as follows...
qt_add_library(NovaLib STATIC) qt_add_qml_module(NovaLib URI Nova ...) qt_add_executable(app main.cpp) qt_add_qml(app URI MyApp VERSION 1.0 QML_FILES main.qml)
then I need to link to the library plugin
target_link_libraries(app PRIVATE ... NovaLibplugin)
Why is this?
NB: when I say "I need to", I mean that if I don't do it this way then either I get a CMake error (linking SHARED library plugin) or it builds but I get a QML runtime error using
import Nova
(linking STATIC library itself). -
wrote on 24 Nov 2022, 19:56 last edited by
target_link_libraries( ${PROJECT_NAME} path/NovaLib.a ) should work.
1/2