My QtQuick 2 extension plugin shared library is not compiling.
-
Hi,
I want to make a shared library of my project. As default qt creator generates a static library from the generated CMakeLists.txt. When I changed it to the SHARED I got this error:
CMakeLists.txt:33: error: Target "IgniteUIplugin" of type MODULE_LIBRARY may not be linked into another target. One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to executables with the ENABLE_EXPORTS property set.
and Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(IgniteUI VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) find_package(Qt6 6.2 COMPONENTS Quick REQUIRED) qt_add_library(IgniteUI SHARED) qt_add_qml_module(IgniteUI URI IgniteUI VERSION 1.0 QML_FILES IgniteUIControls.qml SOURCES igniteui.cpp igniteui.h ) target_compile_definitions(IgniteUI PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>) target_link_libraries(IgniteUI PRIVATE Qt6::Quick) target_include_directories(IgniteUI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) # Example Project qt_add_executable(ExampleProject example/example.cpp) qt_add_qml_module(ExampleProject URI ExampleProjectApp VERSION 1.0 QML_FILES example/example.qml ) target_link_libraries(ExampleProject PRIVATE Qt6::Quick IgniteUIplugin) target_compile_definitions(ExampleProject PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
Cheers
-
I think this line in my example.cpp:
Q_IMPORT_QML_PLUGIN(IgniteUIPlugin)
is causing these issues. maybe it requires the static library and I am providing it the shared library. Does there is a way to make it to use the shared instead of the static library.
Cheers
-
Don't mean to necro-post, but this forum came up on google and I found a more satisfying solution to the same problem for me.
In the CMakeLists.txt file where I define the plugin, I simply added the following:
qt_add_library(PressureModel STATIC)
To indicate the library as static rather than MODULE_LIBRARY.
Full CMakeLists.txt file I used for reference:
find_package(Qt6 REQUIRED COMPONENTS RemoteObjects) qt_add_library(PressureModel STATIC) qt6_add_qml_module(PressureModel URI PressureModel VERSION 1.0 SOURCES PressureModel.cpp PressureModel.h RESOURCE_PREFIX "/" ) qt6_add_repc_replicas(PressureModel PressureModel.rep) target_link_libraries(PressureModel PUBLIC Qt6::RemoteObjects)