Missing MQTT source file after installation
-
Hello,
So I am trying to make a project involving a MQTT communication between two devices. I followed some guidelines from the internet that made me do this:
cd ~/qt5 git clone https://github.com/qt/qtmqtt.git --branch 5.15 cd ~/qt-build mkdir qtmqtt && cd qtmqtt sudo /opt/Qt5.15/qmake ~/qt5/qtmqtt/qtmqtt.pro sudo make sudo make install
Basically, I cloned the Qt MQTT repository into the existing Qt5 cloned repository I had, then I turned to the build directory and launched qmake for the .pro file, make and make install.
I tried setting up a project of my own with the help of the existing Qt examples. I had some difficulties but I figured out that I had to invoke almost every MQTT source file into the CMakeLists. However, I found a dead end when I saw that I had no
qmqttstringpair.cpp
file./opt/Qt5.15/include/QtCore/qvector.h:355: erreur : undefined reference to `QMqttStringPair::QMqttStringPair(QMqttStringPair const&)'
As a matter of fact, I searched and found the header and source files for all the other classes somewhere in my computer, but for
QMqttStringPair
I wasn't able to find its them. I find it weird and I don't know if I missed something or there was a problem with the Makefile or installation. I also couldn't find clues in the web.I am using an Ubuntu 22.04
Thanks for your help. -
Hi,
@SGaist the error doesn't only appear in that header but in
QMqttConnection.cpp
too. 15 in total for both files. The two files must be callingQMqttStringPair
in their code./usr/bin/ld: CMakeFiles/PCDisplay.dir/home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp.o: in function `QMqttConnection::readAuthProperties(QMqttAuthenticationProperties&)': /home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp:807: undefined reference to `QMqttStringPair::QMqttStringPair(QString const&, QString const&)' /usr/bin/ld: /home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp:807: undefined reference to `QMqttStringPair::~QMqttStringPair()' /usr/bin/ld: CMakeFiles/PCDisplay.dir/home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp.o: in function `QMqttConnection::readConnackProperties(QMqttServerConnectionProperties&)': /home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp:882: undefined reference to `QMqttStringPair::QMqttStringPair(QString const&, QString const&)' /usr/bin/ld: /home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp:882: undefined reference to `QMqttStringPair::~QMqttStringPair()' /usr/bin/ld: CMakeFiles/PCDisplay.dir/home/diego/qt5/qtmqtt/src/mqtt/qmqttconnection.cpp.o: in function `QVector<QMqttStringPair>::copyConstruct(QMqttStringPair const*, QMqttStringPair const*, QMqttStringPair*)': /opt/Qt5.15/include/QtCore/qvector.h:355: undefined reference to `QMqttStringPair::QMqttStringPair(QMqttStringPair const&)' ...
@JoeCFD right now I'm not sure if the build placed the files in the right place.
In/opt/Qt5.15/include/QtMqtt
I have the headers and some other "C code source" files (that I haven't seen before) that only contain something like#include "qmqttauthenticationproperties.h"
and that's it.
The errors I have areundefined reference
so I thought I had to link the cpp files which were installed in~/qt5/mqtt/src/mqtt
Am I doing something wrong? -
@diego-qt said in Missing MQTT source file after installation:
Basically, I cloned the Qt MQTT repository into the existing Qt5 cloned repository I had, then I turned to the build directory and launched qmake for the .pro file, make and make
Just in case, try to clone it outside Qt 5 source for a start, who knows what it picks up.
-
Hello, I'll be posting the solution I found.
First of all, I indeed didn't need to add the .cpp files to the CMakeLists file. The proper solution was to add
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Mqtt REQUIRED) target_link_libraries(mytarget PRIVATE Qt${QT_VERSION_MAJOR}::Mqtt)
Because the librairies were already installed, I only had to invoke them.
But further than that, I also had to compile the .pro file of the qtmqtt repository with the qmake tool from the system, otherwise the MQTT libraries will only be visible for the Qt for Android compiler and not the desktop compiler. Also, it would be better to compile it outside of the build directory just used.
-