Including MQTT wrapper for mosquitto library on windows
-
@Dean21 i am thinking this is because you forgot to add DEPENDPATH
source: https://doc.qt.io/qt-6/qmake-variable-reference.html#dependpath
Specifies a list of directories for qmake to scan, to resolve dependencies. This variable is used when qmake crawls through the header files that you #include in your source code.
when using 3rd party libraries, this method is much more easy and less error prone. https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html
Qt modifies your qmake file for you.
-
@Dean21 I think on Windows you need to link differently (see https://doc.qt.io/qt-6/qmake-variable-reference.html#libs):
unix:LIBS += -L/usr/local/lib -lmath win32:LIBS += c:/mylibs/math.lib
So, you need to use a path to the *.lib file of the library.
"the kit used when I made this project says it is Desktop Qt 6.4.1 MinGW 64-bit for the compiler" - the question is - what compiler was used to build that library? If MSVC was used it is not going to work. You need a MinGW build of the lib.
-
@starkm42 Thanks for the reply, that seemed to work to remove a lot of the linking errors but not I get this one error I havent seen before
:-1: error: No rule to make target 'C:/Users/deanm/Desktop/Uni_Year_3/3rd_year_project/Microscope_GUI_V2/Microscope_GUI/../../../../../../../Program Files/mosquitto/devel/libmosquittoppd.a', needed by 'debug/Microscope_GUI.exe'. Stop.
-
@jsulm This is now my .pro file.
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 #QMAKE_CXXFLAGS += -lmosquitto #INCLUDEPATH += "C:/Program Files/mosquitto/devel" #LIBS += -L"C:/Program Files/mosquitto/devel" -lmosquittopp # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ QMMqttClient.cpp \ main.cpp \ widget.cpp \ HEADERS += \ QMMqttClient.h \ widget.h FORMS += \ widget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittopp else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittoppd else:unix: LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittopp INCLUDEPATH += $$PWD/'../../../../../../../Program Files/mosquitto/devel' DEPENDPATH += $$PWD/'../../../../../../../Program Files/mosquitto/devel' win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittopp.a' else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittoppd.a' else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/mosquittopp.lib' else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/mosquittoppd.lib' else:unix: PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittopp.a'
-
@Dean21 said in Including MQTT wrapper for mosquitto library on windows:
else:unix: PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittopp.a'
Why do you have this?
Your LIBS for Windows are still wrong. -
@jsulm Sorry forgot to untick linux and mac boxes, here is the .pro file, it still has the same error though.
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 QMAKE_CXXFLAGS += -lmosquitto INCLUDEPATH += "C:/Program Files/mosquitto/devel" LIBS += -L"C:/Program Files/mosquitto/devel" -lmosquittopp # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ QMMqttClient.cpp \ main.cpp \ widget.cpp \ HEADERS += \ QMMqttClient.h \ widget.h FORMS += \ widget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittopp else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittoppd INCLUDEPATH += $$PWD/'../../../../../../../Program Files/mosquitto/devel' DEPENDPATH += $$PWD/'../../../../../../../Program Files/mosquitto/devel' win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittopp.a' else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittoppd.a' else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/mosquittopp.lib' else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/mosquittoppd.lib'
Error: :-1: error: No rule to make target 'C:/Users/deanm/Desktop/Uni_Year_3/3rd_year_project/Microscope_GUI_V2/Microscope_GUI/../../../../../../../Program Files/mosquitto/devel/libmosquittoppd.a', needed by 'debug/Microscope_GUI.exe'. Stop.
-
@Dean21 said in Including MQTT wrapper for mosquitto library on windows:
QMAKE_CXXFLAGS += -lmosquitto
Why?
And again: your LIBS for Windows are wrong!
I also don't know why you have static versions if you want to link dynamically:
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/'../../../../../../../Program Files/mosquitto/devel/libmosquittoppd.a'
Remove alls these *.a stuff.
-
@jsulm My bad, this was done with dynamic and this is what was generated in the .pro file now.
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 QMAKE_CXXFLAGS += -lmosquitto INCLUDEPATH += "C:/Program Files/mosquitto/devel" LIBS += -L"C:/Program Files/mosquitto/devel" -lmosquittopp # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ QMMqttClient.cpp \ main.cpp \ widget.cpp \ HEADERS += \ QMMqttClient.h \ widget.h FORMS += \ widget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittopp else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../../../../../Program Files/mosquitto/devel/' -lmosquittoppd INCLUDEPATH += $$PWD/'../../../../../../../Program Files/mosquitto/devel' DEPENDPATH += $$PWD/'../../../../../../../Program Files/mosquitto/devel'
This now gives these errors:
:-1: error: cannot find -lmosquittoppd
:-1: error: cannot find -lmosquittod
:-1: error: collect2.exe: error: ld returned 1 exit status -
@Dean21 wait are you using the same compiled library that you used for linux on windows without recompiling or getting new binaries compiled for windows ?
@Dean21 said in Including MQTT wrapper for mosquitto library on windows:
@jsulm I am not sure what compiler was used to compile the library, but as I have had this working in Qt creator before on linux with the same library I assumed it would work fine on windows
-
for adding a test library called NemaTode, after following the guide https://doc.qt.io/qtcreator/creator-project-qmake-libraries.html
this is what my qmake looks like
QT += core gui positioning greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ gpssource.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ gpssource.h \ mainwindow.h # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../third_party_libs/NemaTode/lib/ -lNemaTode else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../third_party_libs/NemaTode/lib/ -lNemaTode else:unix: LIBS += -L$$PWD/../../third_party_libs/NemaTode/lib/ -lNemaTode INCLUDEPATH += $$PWD/../../third_party_libs/NemaTode/include/nmeaparse DEPENDPATH += $$PWD/../../third_party_libs/NemaTode/include/nmeaparse FORMS += \ GPSCordinatesDisplay.ui
mine does not have LIB or INCLUDEPATH
try removing all manual additions, just sticking to the guide would be my suggestion.