I have tried cross-compiling some small C++ code for a Raspberry Pi Model 3b using my Windows machine via Ubuntu-20.04 on WSL2. It uses the Paho MQTT C and C++ libraries to subscribe to and sometimes publish some messages. I'm pretty sure that most of it works since MQTT subscriptions work, as well as publishing messages using a QoS of 0.
However, when publishing with a QoS of 1 or 2, I get a runtime error:
MQTT error [-9]: Invalid QoS value
When I try publishing with a QoS less than 0 or greater than 2, I get this instead:
MQTT error [-9]: Bad QoS
I have compiled the same code in the RPi itself and the code runs without any issues.
I'm not completely sure what is happening, but I tried checking why I'm getting the same reason code but different error messages. It appears that the Bad QoS
message is written in mqtt/message.h, which can be found in the C++ library, while the Invalid QoS Value
can be found in MQTTAsync.c, from the C library.
Just fixed this issue a few days ago. Inspected the predefined targets of the RPi's gcc and as it turns out, it's slightly different: march
is armv6+fp
instead of armv8
I also edited my CMakeLists.txt to perform find_package
on both the eclipse-paho-mqtt-c
and PahoMqttCpp
packages, and fixed the target_link_libraries
line, targetting the link libraries in a more 'specific' way:
target_link_libraries(myproject PahoMqttCpp::paho-mqttpp3 eclipse-paho-mqtt-c::paho-mqtt3as)
I'm actually unsure which one fixed my issues, I'm currently not willing to re-build the toolchain for the armv8
march just to check if the march parameter fixed it, since it takes a little under 30mins.