including a new package in a node

Hi guys,

I'm trying to add a random number generator to the scan n plan application and its proving to be more difficult than I thought it would be. I found a package https://github.com/ros-planning/rando... that I want to include.

I installed the .deb and can find the packing using rospack find.

I added random_numbers in the find_package(catkin REQUIRED COMPONENTS ) and catkin_package() sections of my top level cmake file. I also added depend tag of random_numbers in my top level package.xml file.

in the C++ file I want to use the random number functions, I included the .h as #include random_numbers/random_numbers.h

I then instantiate an instance as random_numbers::RandomNumberGenerator generator;

I keep getting the following error message: error: undefined reference to random_numbers::RandomNumberGenerator::RandomNumberGenerator()'

any thoughts on what I'm missing? this is probably the first thing I've tried that really deviates from the intro.

edit retag close merge delete

Sort by » oldest newest most voted

undefined reference is a linking error; it usually means that your target isn't linked against one of the libraries that it is using.

Linking is done by the cmake target_link_libraries command, so you probably need to update that for your target.

more

is that still going to be done in the top level cmake? is there ever a time that I do things in the node cmake?

( 2019-03-13 06:46:42 -0600 )edit

The "top-level CMake"? Can you clarify what you mean by that?

( 2019-03-13 09:10:41 -0600 )edit

I guess there isnt a cmake in the top level source file like I was thinking. The "top level" I'm referring to would be the main application level process I guess. Particularly in this case for the training project that's the "myworkcell_core" node.

( 2019-03-13 09:23:52 -0600 )edit

No, for typical ROS development environments there is no top-level CMakeLists.txt -- or at least, not one that is created / managed by users.

Note: there typically also isn't a CMakeLists.txt` per node, but per package.

( 2019-03-13 09:28:42 -0600 )edit

Ok, yeah I can see the difference. In the "myworkcell_core" package I have two nodes. So if I'm trying to use this in a different package that would be where I want to modify the cmake then?

( 2019-03-13 09:33:48 -0600 )edit

So if I'm trying to use this in a different package

what is "this"?

( 2019-03-13 09:49:31 -0600 )edit

This random number generator package. I want to use it in the "fake_ar_publisher" package so it would be included in that package cmake? It is a complete package though, so does it need to be added as a package in my top level source directory (catkin_ws/src)? I'll reiterate at this point that I can already find the package using rospack find in my workspace.

( 2019-03-13 09:54:57 -0600 )edit

Please don't take this as me not wanting to explain things to you, but I'd suggest taking a look at the Catkin documentation. Especially the Resolving dependencies section.

( 2019-03-13 09:59:32 -0600 )edit