Probleme beim Umstieg von qmake auf cmake
-
Hallo zusammen,
ich wollte jetzt mal ein Qt Projekt von qmake auf cmake umstellen. Leider bekomme ich beim erstellen einer Library immer nur Fehler.
Der Inhalt der qmake.pro:
message(gc-ui project dir: $${PWD}) include(../qmake-target-platform.pri) include(../qmake-destination-path.pri) DESTDIR = $$PWD/../binaries/$$DESTINATION_PATH OBJECTS_DIR = $$PWD/build/$$DESTINATION_PATH/.obj MOC_DIR = $$PWD/build/$$DESTINATION_PATH/.moc RCC_DIR = $$PWD/build/$$DESTINATION_PATH/.qrc UI_DIR = $$PWD/build/$$DESTINATION_PATH/.ui QT += qml quick sql xml location TEMPLATE = app CONFIG += c++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 INCLUDEPATH += source \ ../gc-lib/source \ ../lib-jsonrpc/source \ ../lib-datad/source \ ../lib-cfg/source \ ../lib-db/source \ ../lib-geo/source \ ../lib-gc/source SOURCES += source/main.cpp RESOURCES += views.qrc \ images.qrc \ assets.qrc \ components.qrc LIBS += -L$$PWD/../binaries/$$DESTINATION_PATH -lgc-lib -ldatad -lcfg -ldb -lgeo -ljsonrpc -lgc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH += $$PWD # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = PLATFORM_WIN { message(gc-ui: Win Special) QT_ANGLE_PLATFORM = D3D9 LIBS += -L"d:/Entwicklung/Qt/Tools/OpenSSL/Win_x64/bin/" -llibcrypto-1_1-x64 -llibssl-1_1-x64 } # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += \ android/AndroidManifest.xml \ android/build.gradle \ android/gradle/wrapper/gradle-wrapper.jar \ android/gradle/wrapper/gradle-wrapper.properties \ android/gradlew \ android/gradlew.bat \ android/res/values/libs.xml include($$PWD/../openssl/android/openssl.pri)
Das CMakeLists.txt habe ich wie folgt erstellt:
cmake_minimum_required(VERSION 3.10) set(APP "gc-ui") project(${APP} VERSION 1.0.0) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -O2 -Wall -W -D_REENTRANT -fPIC") set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) find_package(Qt5 COMPONENTS Core REQUIRED) find_package(Qt5 COMPONENTS Gui REQUIRED) find_package(Qt5 COMPONENTS Qml REQUIRED) find_package(Qt5 COMPONENTS Quick REQUIRED) find_package(Qt5 COMPONENTS Location REQUIRED) include_directories(${Qt5Core_INCLUDE_DIRS}) include_directories(${Qt5Gui_INCLUDE_DIRS}) include_directories(${Qt5Qml_INCLUDE_DIRS}) include_directories(${Qt5Quick_INCLUDE_DIRS}) include_directories(${Qt5Location_INCLUDE_DIRS}) include_directories("source/") include_directories("../gc-lib/source/") include_directories("../lib-gc/source/") include_directories("../lib-datad/source/") include_directories("../lib-jsonrpc/source/") include_directories("../lib-geo/source/") include_directories("../lib-cfg/source/") include_directories("../lib-db/source/") link_directories("../gc-lib/") link_directories("../lib-datad/") link_directories("../lib-jsonrpc/") link_directories("../lib-geo/") link_directories("../lib-cfg/") link_directories("../lib-db/") link_directories("../lib-gc/") if(NOT DEFINED HEADERS) file(GLOB HEADERS source/*.h) endif() if(NOT DEFINED SOURCES) file(GLOB HEADERS source/*.cpp) endif() if(NOT DEFINED RESOURCES) file(GLOB RESOURCES *.qrc) endif() source_group("Header Files" FILES ${HEADERS}) source_group("Source Files" FILES ${SOURCES}) source_group("Resource Files" FILES ${RESOURCES}) add_executable(${APP} ${HEADERS} ${SOURCES} ${RESOURCES}) target_link_libraries( ${APP} Qt5::Core Qt5::Gui Qt5::Qml Qt5::Quick Qt5::Location gc-lib datad gc jsonrpc geo cfg db )
Wenn ich jetzt ein make ausführe bekomme ich folgende Fehlermeldung:
[ 8%] Automatic MOC and UIC for target gc-ui [ 8%] Built target gc-ui_autogen Consolidate compiler generated dependencies of target gc-ui [ 16%] Linking CXX executable gc-ui /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o: in function `QQmlPrivate::QQmlElement<controllers::NavigationController>::~QQmlElement()': main.cpp:(.text._ZN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEED2Ev[_ZN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEED5Ev]+0x1e): undefined reference to `vtable for controllers::NavigationController' /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o: in function `QQmlPrivate::QQmlElement<controllers::NavigationController>::~QQmlElement()': main.cpp:(.text._ZN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEED0Ev[_ZN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEED5Ev]+0x1e): undefined reference to `vtable for controllers::NavigationController' /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o: in function `main': main.cpp:(.text.startup+0x379): undefined reference to `controllers::NavigationController::staticMetaObject' /usr/bin/ld: main.cpp:(.text.startup+0x46b): undefined reference to `controllers::NavigationController::staticMetaObject' /usr/bin/ld: main.cpp:(.text.startup+0x49c): undefined reference to `controllers::NavigationController::staticMetaObject' /usr/bin/ld: main.cpp:(.text.startup+0x2340): undefined reference to `controllers::NavigationController::staticMetaObject' /usr/bin/ld: main.cpp:(.text.startup+0x23ac): undefined reference to `controllers::NavigationController::staticMetaObject' /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o:(.data.rel.ro._ZTIN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE[_ZTIN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE]+0x10): undefined reference to `typeinfo for controllers::NavigationController' /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE[_ZTVN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE]+0x10): undefined reference to `controllers::NavigationController::metaObject() const' /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE[_ZTVN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE]+0x18): undefined reference to `controllers::NavigationController::qt_metacast(char const*)' /usr/bin/ld: CMakeFiles/gc-ui.dir/source/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE[_ZTVN11QQmlPrivate11QQmlElementIN11controllers20NavigationControllerEEE]+0x20): undefined reference to `controllers::NavigationController::qt_metacall(QMetaObject::Call, int, void**)' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goWpMapView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goGcMapView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goGcEditView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goGcDescViewShort()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goWpEditView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goGcDescViewHint()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goWpNoteView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goDashboardView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goPqImportBackView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goGcDescView()' /usr/bin/ld: /home/martin/Entwicklung/qt/qt_gc_cmake/gc-ui/../gc-lib/libgc-lib.so: undefined reference to `controllers::NavigationController::goGcDescViewLong()' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/gc-ui.dir/build.make:283: gc-ui] Fehler 1 make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/gc-ui.dir/all] Fehler 2 make: *** [Makefile:91: all] Fehler 2
Ein Aufruf von make in dem qmake Projekt gibt keinen Fehler und das Programm wird fehlerfrei compiliert.
Hat einer von Euch eine Idee woran das Problem liegen könnte?Danke für Eure Hilfe.
gruss
martin -
@msauer75 said in Probleme beim Umstieg von qmake auf cmake:
include_directories(${Qt5
Das ist unnötig.
file(GLOB
Das sollte nicht genutzt werden. Die sourcen bitte ordentlich einzeln aufführen.
${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}
Was soll das? Unnötig.
-pipe -O2
dito
controllers::NavigationController
in welcher Source-Datei ist das? Ist es eine statische oder dynamische lib oder ist es direkt mit in diesem Projekt?
Wenn dynamische lib - wird die Klasse korrekt exportiert? -
@msauer75 said in Probleme beim Umstieg von qmake auf cmake:
include_directories(${Qt5
Das ist unnötig.
file(GLOB
Das sollte nicht genutzt werden. Die sourcen bitte ordentlich einzeln aufführen.
${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}
Was soll das? Unnötig.
-pipe -O2
dito
controllers::NavigationController
in welcher Source-Datei ist das? Ist es eine statische oder dynamische lib oder ist es direkt mit in diesem Projekt?
Wenn dynamische lib - wird die Klasse korrekt exportiert?Danke Dir schon mal für deine Tips. Die unnötigen Punkte habe ich aus diversen Infos / Tutorials wo die das so gemacht haben.
Bezgl.
controllers::NavigationController
Die Klasse ist in einem include File in der Library gc-lib:
namespace controllers { class GCLIBSHARED_EXPORT NavigationController : public QObject { Q_OBJECT public: explicit NavigationController(QObject* _Parent = nullptr) : QObject(_Parent) {} signals: void goDashboardView(); void goGcListView(); void goGcEditView(); void goGcMapView(); void goGcSearchView(); void goGcDescViewShort(); void goGcDescViewLong(); void goGcDescViewHint(); void goAdminView(); void goWpEditView(); void goWpNoteView(); void goWpMapView(); void goPqImportFileOpenView(); void goPqImportBackView(); void goGsakListView(); void goGcDescView(); };
Die einzelnen FUnktionen sind Signale, die aus meiner masterview.qml kommen:
Connections { target: masterController.ui_navctrl onGoDashboardView: contentFrame.replace("qrc:/views/DashboardView.qml") onGoGcListView: contentFrame.replace("qrc:/views/GcListView.qml") onGoGcEditView: contentFrame.replace("qrc:/views/GcEditView.qml", {selectedCache: masterController.ui_cache}) onGoGcMapView: contentFrame.push("qrc:/views/GcMapView.qml", {selectedCache: masterController.ui_cache}) onGoGcSearchView: contentFrame.replace("qrc:/views/GcSearchView.qml") onGoGcDescViewLong: contentFrame.replace("qrc:/views/GcDescView.qml", {dispText: masterController.ui_cache.ui_desclang, headerText1: "Beschreibung lang"}) onGoGcDescViewShort: contentFrame.replace("qrc:/views/GcDescView.qml", {dispText: masterController.ui_cache.ui_desckurz, headerText1: "Beschreibung kurz"}) // onGoGcDescViewHint: contentFrame.replace("qrc:/views/GcDescView.qml", {dispText: masterController.ui_cache.ui_hint, headerText1: "Hinweis"}) onGoGcDescView: contentFrame.push("qrc:/views/GsakDescView.qml", {cacheItem: masterController.ui_cache}) onGoAdminView: contentFrame.replace("qrc:/views/AdminView.qml") onGoWpEditView: contentFrame.replace("qrc:/views/WpListView.qml") onGoWpNoteView: contentFrame.replace("qrc:/views/WpNoteView.qml") onGoWpMapView: contentFrame.replace("qrc:/views/WpMapView.qml", {selectedCache: masterController.ui_cache, wpListe: masterController.ui_wpliste}) onGoPqImportFileOpenView: contentFrame.replace("qrc:/views/PqImportView.qml", {importDone: false, pqImport: masterController.ui_pqimport}) onGoPqImportBackView: contentFrame.replace("qrc:/views/PqImportView.qml", {importDone: true, pqImport: masterController.ui_pqimport}) onGoGsakListView: contentFrame.replace("qrc:/views/GsakListView.qml", {onViewLoad: masterController.ui_gsak.onViewLoad()}) }
gruss
martin -
@msauer75 said in Probleme beim Umstieg von qmake auf cmake:
GCLIBSHARED_EXPORT
Wird dies korrekt gesetzt wenn die lib gebaut wird bzw. genutzt wird?
Ist die Lib statisch oder dynamisch.Die unnötigen Punkte habe ich aus diversen Infos / Tutorials wo die das so gemacht haben.
Schlechte Beispiele gewählt :)
-
@msauer75 said in Probleme beim Umstieg von qmake auf cmake:
include_directories(${Qt5
Das ist unnötig.
file(GLOB
Das sollte nicht genutzt werden. Die sourcen bitte ordentlich einzeln aufführen.
${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}
Was soll das? Unnötig.
-pipe -O2
dito
controllers::NavigationController
in welcher Source-Datei ist das? Ist es eine statische oder dynamische lib oder ist es direkt mit in diesem Projekt?
Wenn dynamische lib - wird die Klasse korrekt exportiert? -
@msauer75 said in Probleme beim Umstieg von qmake auf cmake:
die sourcen einzeln in add_executable?
SET(SOURCES
eins.cpp
eins.h
zwei.cpp
...
)add_executable(blub ${SOURCES})
-
@msauer75 said in Probleme beim Umstieg von qmake auf cmake:
die sourcen einzeln in add_executable?
SET(SOURCES
eins.cpp
eins.h
zwei.cpp
...
)add_executable(blub ${SOURCES})
Nachdem ich jetzt alle Resourcen (*.cpp, *.h, *.qrc) einzelnen in die jeweiligen CMakeLists.txt Dateien hinzugefügt habe kann ich das ganze Projekt compilieren und die Anwendung auch starten.
Danke dir für deine Hilfe.
gruss
maritn