Find Package Failed for MQTT Simple Application
-
Hello Everyone,
I wanted to test the simple MQTT application from the example project.
But things are not working well for me.
As per the documentation, available on this https://doc.qt.io/qt-6.2/qtmqtt-index.html page.
I have to use the following in myCMakeLists.txt
file, and I updated my file as below.cmake_minimum_required(VERSION 3.16) project(MQTT_Application VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.2 COMPONENTS Quick REQUIRED) find_package(Qt6 REQUIRED COMPONENTS Mqtt) qt_add_executable(appMQTT_Application main.cpp ) qt_add_qml_module(appMQTT_Application URI MQTT_Application VERSION 1.0 QML_FILES main.qml ) set_target_properties(appMQTT_Application PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(appMQTT_Application PRIVATE Qt6::Quick) target_link_libraries(appMQTT_Application PRIVATE Qt6::Mqtt) install(TARGETS appMQTT_Application BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
But, I am getting the following error.
/home/xpress_embedo/Work/ESP32/ControlDevicesMQTT/MQTT_Application/CMakeLists.txt:9: error: Found package configuration file: /opt/Qt/6.2.4/gcc_64/lib/cmake/Qt6/Qt6Config.cmake but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND. Reason given by package: Failed to find Qt component "Mqtt". Expected Config file at "/opt/Qt/6.2.4/gcc_64/lib/cmake/Qt6Mqtt/Qt6MqttConfig.cmake" does NOT exist``` As can be seen in the above logs, the Qt version is 6.2.4 Can someone help me with this issue?
-
@SGaist Thank You for your answer. I still find it difficult, but finally, I am able to fix this, with your help and some help from StackOverflow.
I am pasting the link which helps me below.
https://stackoverflow.com/questions/68928310/build-specific-modules-in-qt6-i-e-qtmqtt/71984521?noredirect=1#comment132724929_71984521One Question, on the documentation page, 4 examples are given, from where can I download them?
This video can help others
https://youtu.be/DGB0GfFRqPo
And also the below-mentioned link.
https://embeddedlaboratory.blogspot.com/2023/01/getting-started-with-mqtt-using-qt.html -
Hi,
Did you build and install the module before using it ?
-
Usual cmake build commands:
mkdir build_qtmqtt cd build_qtmqtt /path/to/Qt6/bin/qt-cmake /path/to/qtmqtt_sources/ /path/to/Qt6/bin/qt-cmake -build . -parallel /path/to/Qt6/bin/qt-cmake install
-
@SGaist said in Find Package Failed for MQTT Simple Application:
Usual cmake build commands:
mkdir build_qtmqtt cd build_qtmqtt /path/to/Qt6/bin/qt-cmake /path/to/qtmqtt_sources/ /path/to/Qt6/bin/qt-cmake -build . -parallel /path/to/Qt6/bin/qt-cmake install
Thank You for some hints, I have a very basic understanding of CMake, and I will share what I have done till now, and maybe you can give me some more hints to fix my problem.
Qt MQTT module link is this: https://code.qt.io/cgit/qt/qtmqtt.git/
As a first step, I cloned this module using the commandgit clone https://code.qt.io/cgit/qt/qtmqtt.git
, and after cloning I switched to branch6.2.4
, as this is the Qt version installed on my laptop.
I opened the terminal and tried to configure the project using the following command.mkdir build cd build /opt/Qt/Tools/CMake/bin/cmake ..
And I get the following error, also shown in the screenshot below.
CMake Error at CMakeLists.txt:19 (find_package): Could not find a package configuration file provided by "Qt6" (requested version 6.2.4) with any of the following names: Qt6Config.cmake qt6-config.cmake Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR" to a directory containing one of the above files. If "Qt6" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred! See also "/home/xpress_embedo/Work/Qt/DontCommit/qtmqtt/build/CMakeFiles/CMakeOutput.log".
From the message, it is clear thatqt6-config.cmake
is missing, and I think the reason is obvious, as I have to provide the path of this.
Anyways, as a next step, what I did is, I opened the project inQtCreator
and builds it and it build properly.
As per the message the library is created successfully.
[31/31 4.1/sec] Creating library symlink lib/libQt6Mqtt.so.6 lib/libQt6Mqtt.so
I think CMake is also going to do the same thing, but what are the next steps, how can I use this library?
Another question is why the steps mentioned in the documentation page is different.
https://doc.qt.io/qt-6/qtmqtt-index.htmlSorry for stupid questions, I am trying to learn.
-
- the path I used in my example above was on purpose. Look into your Qt 6.2.4 folder, you'll find qt-cmake in the bin folder. That would have avoided the round trip through Qt Creator. Note that it's not wrong to use Qt Creator at all, I am just used to the terminal.
- Either add a custom step that calls cmake install or do it on the terminal as shown above.
- the instructions in the documentation are for using the module and are correct from that point of view.
-
@SGaist Thank You for your answer. I still find it difficult, but finally, I am able to fix this, with your help and some help from StackOverflow.
I am pasting the link which helps me below.
https://stackoverflow.com/questions/68928310/build-specific-modules-in-qt6-i-e-qtmqtt/71984521?noredirect=1#comment132724929_71984521One Question, on the documentation page, 4 examples are given, from where can I download them?
This video can help others
https://youtu.be/DGB0GfFRqPo
And also the below-mentioned link.
https://embeddedlaboratory.blogspot.com/2023/01/getting-started-with-mqtt-using-qt.html -
They are in the sources you already cloned.