Weird linking errors using Qt,ROS and cmake
-
Hi guys,
I've been programming in Qt for a while and now i jumped out the IDE to use it with other stuff, mainly ROS. Given this, i'm compiling my stuff with cmake and all went fine until today. I've been able to compile and run GUIs and all of the programs that i've been working on successfully.
Setting up qt libraries in CMakeLists.txtMESSAGE( STATUS "-----> Current Qt Installation Path : " ${CURRQTPREFIX}) set(CMAKE_PREFIX_PATH ${CURRQTPREFIX}) find_package(Qt5 COMPONENTS Core) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(QT_DIR ${CURRQTPREFIX}/include) include_directories(${QT_DIR} ${QT_DIR}/QtCore) set(qt_LIBRARIES libQt5Core.so ) link_directories(${CURRQTPREFIX}/lib) add_definitions(-DQT_THREAD_SUPPORT)
So if i run this (only part of the whole CMakeLists.txt):
## LOCALIZATION ## ###################################################################### set(LOCALIZATION_DIR ${PROJECT_DIRECTORY}/localization_node) include_directories(${LOCALIZATION_DIR}/include) set(LOCALIZATION_SRC_DIR ${LOCALIZATION_DIR}/src) # Add new source files to folder /src and add them here for compilation set(localization_SRC ${LOCALIZATION_SRC_DIR}/main_localization.cpp ${LOCALIZATION_SRC_DIR}/Angle.cpp ${LOCALIZATION_SRC_DIR}/Vec.cpp ${LOCALIZATION_SRC_DIR}/RLE.cpp ${LOCALIZATION_SRC_DIR}/ScanLines.cpp ${LOCALIZATION_SRC_DIR}/kmeans.cpp ${LOCALIZATION_SRC_DIR}/imageprocessor.cpp ${LOCALIZATION_SRC_DIR}/configserver.cpp ${LOCALIZATION_SRC_DIR}/localization.cpp ${LOCALIZATION_SRC_DIR}/blackflycam.cpp) # Add new header files to folder /include and add them here for compilation set(localization_MOC_H ${LOCALIZATION_DIR}/include/configserver.h ${LOCALIZATION_DIR}/include/localization.h) qt5_wrap_cpp(localization_CPP ${localization_MOC_H}) add_executable(localization_node ${localization_SRC} ${localization_CPP}) set_target_properties(localization_node PROPERTIES COMPILE_FLAGS "-fPIC") target_compile_features(localization_node PRIVATE cxx_range_for) target_link_libraries(localization_node ${catkin_LIBRARIES} ${qt_LIBRARIES} ${opencv_LIBRARIES} ${flycap_LIBRARIES}) add_dependencies(localization_node ${PROJECT_NAME}_gencpp) ######################################################################
If i run this in my computer (64bit, intel, Ubuntu 16.04 LTS) it runs fine, as it should. Now, if i upload the exact same this to my robot's computer (64bit, intel, Ubuntu Server 16.04 LTS) it doesn't and throws linking errors of libraries i'm not even using ...
//usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: undefined reference to `QLocaleData::validateChars(QString const&, QLocaleData::NumberMode, QByteArray*, int, bool) const' //usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5: undefined reference to `QDateTimeParser::sectionFormat(int) const' //usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5: undefined reference to `QAbstractTransitionPrivate::get(QAbstractTransition*)' collect2: error: ld returned 1 exit status
I installed Qt 5.7 in /opt/Qt which is ${CURRQTPREFIX}.
The problem came when adding blackflycam.cpp. This source file includes some libraries that i was including on a previous file, so, whats the catch ??
Thanks in advance !
-
See the Qt's CMake docs for the recommended way of doing it; you have some unneeded steps. Not sure why you're getting a link error, I would double check that all the variables you include in target_link_libraries aren't adding something unexpected.
-
Thanks !
Yes, i have some stuff that doesnt quite need to be there, but it doesnt hurt. I removed all possible linkings and made them "hardcoded". If i add blackflycam.cpp to the sources, therefore it is compiled, i get those errors. If i dont, all runs smooth. The thing is, the code that i replaced with that file, has the exact same includes and non of them are qt-related, so i dont know what the hell is going on here !