Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
6.2.7, 6.4.2, 6.5.0 Beta1
Description
Attached are 2 projects which consist of a simple static QML plugin and a simple application that uses that plugin:
└── MyModule ├── CMakeLists.txt ├── MyItem.qml └── MyApp ├── CMakeLists.txt ├── main.cpp ├── main.qml
Relevant parts of <ROOT>/MyModule/CMakeLists.txt:
project(MyModule) if (NOT DEFINED MY_QML_DIR) set(MY_QML_DIR ${CMAKE_SOURCE_DIR}/../qml) endif() set(QT_QML_OUTPUT_DIRECTORY ${MY_QML_DIR}) qt_add_qml_module(MyModule URI MyModule VERSION 1.0 STATIC QML_FILES MyItem.qml )
Relevant parts of <ROOT>/MyApp/CMakeLists.txt:
project(MyApp) if (NOT DEFINED MY_QML_DIR) set(MY_QML_DIR ${CMAKE_SOURCE_DIR}/../qml) endif() qt_add_executable(appMyApp main.cpp ) qt_add_qml_module(appMyApp URI MyApp VERSION 1.0 IMPORTS MyModule IMPORT_PATH ${MY_QML_DIR} QML_FILES main.qml ) target_link_directories(appMyApp PRIVATE ${MY_QML_DIR}/MyModule) target_link_libraries(appMyApp PRIVATE Qt6::Quick MyModuleplugin)
Relevant parts of <ROOT>/MyApp/main.cpp:
int main(int argc, char *argv[]) { Q_IMPORT_QML_PLUGIN(MyModulePlugin); // ... }
Steps to reproduce
- Build <ROOT>/MyModule/CMakeLists.txt as a standalone project
- Build <ROOT>/MyApp/CMakeLists.txt as a standalone project (using the same Kit as above)
Outcome
Step #1 builds fine, but Step #2 fails:
/usr/bin/ld: <ROOT>/qml/MyModule/libMyModuleplugin.a(MyModuleplugin_MyModulePlugin.cpp.o): in function `qt_plugin_instance_MyModulePlugin()': MyModuleplugin_MyModulePlugin.cpp:(.text+0xc2): undefined reference to `qml_register_types_MyModule()' /usr/bin/ld: <ROOT>/qml/MyModule/libMyModuleplugin.a(MyModuleplugin_MyModulePlugin.cpp.o): in function `QtPrivate::QMetaTypeForType<MyModulePlugin>::getDefaultCtr()::{lambda(QtPrivate::QMetaTypeInterface const*, void*)#1}::_FUN(QtPrivate::QMetaTypeInterface const*, void*)': MyModuleplugin_MyModulePlugin.cpp:(.text._ZZN9QtPrivate16QMetaTypeForTypeI14MyModulePluginE13getDefaultCtrEvENUlPKNS_18QMetaTypeInterfaceEPvE_4_FUNES5_S6_[_ZZN9QtPrivate16QMetaTypeForTypeI14MyModulePluginE13getDefaultCtrEvENUlPKNS_18QMetaTypeInterfaceEPvE_4_FUNES5_S6_]+0x2e): undefined reference to `qml_register_types_MyModule()'
...even though nm -C libMyModuleplugin.a shows that qml_register_types_MyModule() exists.
Workaround
Merge both projects into a single CMake tree by adding <ROOT>/CMakeLists.txt (which is already provided in the attachment):
cmake_minimum_required(VERSION 3.16) project(MyMergedProject) set(MY_QML_DIR ${CMAKE_SOURCE_DIR}/qml) add_subdirectory(MyModule) add_subdirectory(MyApp)
This lets us successfully build and run the application.
Notes
- When merging into a single project tree, _Q_IMPORT_QML_PLUGIN()_ is not necessary
- When building MyApp as standalone project, building/linking completes without errors if _Q_IMPORT_QML_PLUGIN()_ is removed. However, this means the QML resources become unavailable at runtime.
Attachments
Issue Links
- duplicates
-
QTBUG-110243 Resources are lost when linking static libraries using CMake build system in a separate project
- Reported
- relates to
-
QTBUG-110243 Resources are lost when linking static libraries using CMake build system in a separate project
- Reported
-
QTBUG-91448 Undefined resource symbols when linking app with a static Qt without qmake and CMake
- Open