Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.6.1
-
None
Description
Consider the following simple Qt app
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(module_includes)
find_package(Qt6Coap 6.0.0 REQUIRED)
add_executable(module_includes_exe "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
target_link_libraries(module_includes_exe Qt6::Coap)
// main.cpp #include <QCoapClient> #include <QtCoap/QCoapClient> #include <QtCoap> #include <QtCoap/QtCoap> int main(int, char **) { QCoapClient localQCoapClient; return 0; }
Trying to build this on QNX will fail with the following linker error:
/opt/qnx710/host/linux/x86_64/usr/bin/x86_64-pc-nto-qnx7.1.0-ld: warning: libQt6Network.so.6, needed by /home/qt/work/install/target/lib/libQt6Coap.so.6.8.0, not found (try using -rpath or -rpath-link) /opt/qnx710/host/linux/x86_64/usr/bin/x86_64-pc-nto-qnx7.1.0-ld: /home/qt/work/install/target/lib/libQt6Coap.so.6.8.0: undefined reference to `QUdpSocket::QUdpSocket(QObject*)@Qt_6' /opt/qnx710/host/linux/x86_64/usr/bin/x86_64-pc-nto-qnx7.1.0-ld: /home/qt/work/install/target/lib/libQt6Coap.so.6.8.0: undefined reference to `QSslKey::QSslKey(void*, QSsl::KeyType)@Qt_6' /opt/qnx710/host/linux/x86_64/usr/bin/x86_64-pc-nto-qnx7.1.0-ld: /home/qt/work/install/target/lib/libQt6Coap.so.6.8.0: undefined reference to `QDtls::setPeer(QHostAddress const&, unsigned short, QString const&)@Qt_6' /opt/qnx710/host/linux/x86_64/usr/bin/x86_64-pc-nto-qnx7.1.0-ld: /home/qt/work/install/target/lib/libQt6Coap.so.6.8.0: undefined reference to `operator<<(QDebug, QAbstractSocket::SocketError)@Qt_6' ...
Adding -Wl,-rpath-link,/home/qt/work/install/target/lib to the linker command line fixes the error.
The problem resembles QTBUG-86533 but is not quite the same.
Here, we lack a IMPORT_LINK_DEPENDENT_LIBRARIES property of the Qt6::Coap target that's set up in Qt6CoapTargets.cmake. If I add the property and set it to Qt6::Network then CMake adds the -rpath-link flag and linking succeeds.
Other Qt6::Foo targets have IMPORT_LINK_DEPENDENT_LIBRARIES set. For example Qt6::Gui's property contains Qt6::DBus.
The QtCoap module is set up like this:
qt_internal_add_module(Coap SOURCES ... LIBRARIES Qt::CorePrivate Qt::Network PUBLIC_LIBRARIES Qt::Core PRIVATE_MODULE_INTERFACE Qt::CorePrivate Qt::Network GENERATE_CPP_EXPORTS )
If I change the Qt::Network target under LIBRARIES to Qt6::Network, CMake adds the IMPORT_LINK_DEPENDENT_LIBRARIES property to the exported Qt6::Coap and linking of the example program succeeds.