ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How should I modify my CMakeLists file to build a Qt Ros node? [closed]

asked 2013-02-22 15:36:06 -0500

Ricardo gravatar image

updated 2014-04-20 14:09:40 -0500

ngrennan gravatar image

Hello,

I am trying to build a ros node with some code I developed to control a robot using some qt libraries. I checked some tutorials but I can not make it build.

I have three files: the main.cpp that creates and call and object of type (which is in client.cpp and client.h). The three files uses qt objects or functions (mainly network and gui elements).

This is how my manifest.xml and CMakeLists.txt look like:

<package>
  <description brief="robot">

     robot

  </description>
  <author>Me</author>
  <license>BSD</license>
  <review status="unreviewed" notes=""/>
  <url></url>
  <depend package="std_msgs"/>
  <depend package="roscpp"/>
  <depend package="rospy"/>
  <depend package="opencv2"/>
  <depend package="sensor_msgs"/>
  <depend package="geometry_msgs"/>
  <depend package="image_geometry"/>
  <depend package="tf"/>
  <depend package="qt_build"/>
  <rosdep name="libqt4-dev"/>
  <rosdep name="qt4-qmake"/>

</package>

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Setup
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()

rosbuild_include(qt_build qt-ros)

# Call any of qt-ros' components
rosbuild_prepare_qt4(QtCore QtGui QtNetwork)


#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/*.hpp src/client.h)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)


#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#rosbuild_add_library(cliento src/client.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(client src/main.cpp) 
rosbuild_add_executable(robot_client ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(robot_client ${QT_LIBRARIES})
#target_link_libraries(example ${PROJECT_NAME})

The problem is that if I make a library with my client.cpp (using rosbuild_add_library(cliento src/client.cpp)), "cmake ." or "rosmake" tells me there is a segmentation fault or "terminate called after throwing an instance of 'St9bad_alloc' what(): std::bad_alloc " respectively. And if I do not create the library and include the sources inside the rosbuild_add_executable instruction I will get undefined references from the linking process.

May someone tell me how to properly write my CMakeLists.txt in order to use qt and ros?

I will really appreciate your help.

Ricardo

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by 130s
close date 2013-02-24 17:42:44

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-02-23 01:29:50 -0500

Ricardo gravatar image

I found the solution to my problem:

As I was using my previous project it had some cache files from the previous buildings that were creating conflicts. I deleted them.

After I manage to pass that issue I found many undefined references due to some third party libraries I am using. I included those third-party libraries. The final CMakeLists.txt file looks like this:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Setup
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()

rosbuild_include(qt_build qt-ros)

# Call any of qt-ros' api, e.g.
rosbuild_prepare_qt4(QtCore QtGui QtNetwork)

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#third party libraries
FIND_LIBRARY( SENSOR_LIBRARY sensor ${CMAKE_INSTALL_PREFIX}/lib )
FIND_LIBRARY( QDISPLAY_LIBRARY qdisplay ${CMAKE_INSTALL_PREFIX}/lib )

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/*.hpp src/client.h)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)


#file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/client.cpp src/main.cpp)

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#rosbuild_add_library(cliento src/client.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(client src/main.cpp) 
rosbuild_add_executable(robot_client ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(robot_client ${QT_LIBRARIES} ${SENSOR_LIBRARY} ${QDISPLAY_LIBRARY})
#target_link_libraries(example ${PROJECT_NAME})

I did not change the manifest file.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-22 15:36:06 -0500

Seen: 3,130 times

Last updated: Feb 23 '13