Asa
Asa

Reputation: 11

Error while reading rosbag file using Qt Creator

I am new to both Qt Creator and C++ and I want to make a GUI using Qt Creator to display data given from a rosbag. But I have a problem to import the rosbag into Qt. I tested the code given from Rosbag reader in qtcreator but get the error:

error: cannot find -ltf2_ros
error: cannot find -lrospack
error: cannot find -lroslib
error: cannot find -lroscpp
error: cannot find -lrosconsole_bridge
error: cannot find -lrosbag_storage
error: cannot find -lrosbag

How do I add those libraries?

Upvotes: 1

Views: 463

Answers (1)

Adrien BARRAL
Adrien BARRAL

Reputation: 3604

I think you will have more pertinent responses on the ROS answers website. But I can start to answer to your question.

First thing to do when you start using ROS, is to follow these tutorials : http://wiki.ros.org/ROS/Tutorials (and in particular the 3, 4, and 11).

You can check libraries are installed in the following folder /opt/ros/kinetic/lib/ (if you use ros-kinetic which is the default on ubuntu 16.04).

Then, when you develop a ROS node, do not use Qmake, use catkin and cmake.

A minimal CMake to use catkin and QT will look like this :

cmake_minimum_required(VERSION 2.8.12)
project(librosqt)

find_package(catkin REQUIRED roscpp)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Core)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES librosqt
  CATKIN_DEPENDS roscpp
)

include_directories(include ${Qt5Core_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})


add_library(librosqt src/QRosCallBackQueue.cpp include/librosqt/QRosCallBackQueue.h)

add_executable(test_rosqt_node test/main.cpp test/TestObject.cpp)

target_link_libraries(test_rosqt_node 
   librosqt
   ${catkin_LIBRARIES} Qt5::Core
)

install(TARGETS librosqt
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE
)

Then, if you use catkin. You will have a package.xml in which you will list all your dependendecies (QT, tf2 etc ...). Then before building your ros workspace you can use rodeps install , and this tool will install all your libraries. (see the doc here).

Another important thing to note : Don't forget to source !!!! Before building your node, you will have to source the following files : /opt/ros/kinetic|lunar/setup.bash and your_workspace_home/devel/setup.bash.

If you want to build in QTCreator (with the build button), be sure that qtcreator was launched in a sourced environment.

Upvotes: 1

Related Questions