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

getting a C++ Programm run under ROS

asked 2013-04-19 00:25:30 -0500

Stiebi gravatar image

updated 2014-01-28 17:16:16 -0500

ngrennan gravatar image

hi Im trying to write a RTSP Client for ROS and found live555.com site and there openRTSP / testRTSPClient wich are command line tools that already do what i want. So i thought should not be to hard get that running in ROS. So I created a new package and ctrl+C/V the main file in the src folder and the rest in the Include folder when i try to Compile it now it does not find all the headers. and im dont know how to tell ROS where it should look for all the .hh files.

I tryed adding them in the Cmakelist.txt file with add_subdirectory and include_directories bot it did not work.

So my next try was to move all .cpp and .hh files from all folders/subfolders into the src folder and now I get "undefined reference to" errors for all funktions

I started with ROS a week ago so maybe its some basic thing i missed in the tutorials.

would be nice if someone could help me

EDIT:

that testRTSP .cpp is a Command line tool wich depends on some librarys and allows me to access an rtps- stream. so my plan was to send that stream over a image pipeline to openCV. but i have no idea what i need to change to compile that code with rosmake.

So i have my src/maintest.cpp file wich includes livemedia.hh livemedia.hh is located at ../livemedia/include/livemedia.hh

livemedia itself creates a liblivemedia.a file when compiled.

So do i have to make a livemedia ros package first so it creates a libary? when yes how do i create a library.

edit retag flag offensive close merge delete

Comments

You need to be more explicit about what exactly you did and what exactly your errors are as a result of every step.

dornhege gravatar image dornhege  ( 2013-04-19 00:57:54 -0500 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2013-04-19 01:20:36 -0500

Waterplant gravatar image

updated 2013-04-19 01:32:51 -0500

  1. Create a Package: http://www.ros.org/wiki/ROS/Tutorials/CreatingPackage
  2. go in the CMakeLists.txt and add following line:

    rosbuild_add_executable (example src/example.cpp) target_link_libraries(example ${PCL_LIBRARIES})

PCL is only an example Library. Make sure that your cpp file is placed in src/..

The last step is only to call rosmake [pkg-name]

edit flag offensive delete link more

Comments

thx for your answer but it did not help. im editing my post and make it more specific

Stiebi gravatar image Stiebi  ( 2013-04-19 01:55:01 -0500 )edit
1

answered 2013-04-19 02:12:58 -0500

You are supposed to put all .cpp files into src/ and the headers to include/mypackagename/

If you are lazy and your headers are not needed from the outside, you can also put them in the src folder. Then you can include them as #include "myclass.h" instead of #include <mypackagename/myclass.h>

The undefined reference error is from the linker, which doesn't know where the executable code for the functionality defined in the headers is. This means you either didn't specify a required library or didn't compile all your code.

For the former see Waterplants answer, for the latter make sure you add all your .cpp files to the rosbuild_add_executable command in CMakeLists.txt, e.g.

rosbuild_add_executable (programname src/main.cpp src/somethingelse.cpp src/myclass.cpp)
edit flag offensive delete link more

Comments

already tryed to put all .cpp and .hh files in the src folder but did not work . how do i specify the linker where it finds all the code. what you mean with library? all i use is roscpp as i just have cpp files

Stiebi gravatar image Stiebi  ( 2013-04-19 02:34:50 -0500 )edit

Can you please post the content of your CMakeLists.txt

Felix Endres gravatar image Felix Endres  ( 2013-04-19 05:41:05 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-04-19 00:25:30 -0500

Seen: 6,941 times

Last updated: Apr 19 '13