Ask Your Question
0

Building and linking ros library

asked 2013-10-04 02:39:44 -0600

cschou gravatar image

updated 2013-10-04 03:35:44 -0600

Hi All,

I'm trying to rosbuild a library, which will then be included in several other ROS-packages. Right now, I have successfully created the library in "DeviceHandler" package by:

rosbuild_add_library(Advertiser src/Advertiser.cpp)

This library consists of a class (Advertiser.cpp and Advertiser.hpp) I have exported the following flags in the Manifest.xml of "DeviceHandler":

<export>
<cpp cflags="-I${prefix} -I${prefix}/include/ -I${prefix}/include/DeviceHandler/ -I${prefix}/msg_gen/cpp/include/DeviceHandler -I${prefix}/srv_gen/cpp/include/DeviceHandler" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lAdvertiser"/>
</export>

And I have made my new package (let's call it NewPackage) depend on this "DeviceHandler" package - which builds the "libAdvertiser.so".

So far so good, however, when I try to utilise the library (libAdvertiser.so) in the "NewPackage", it simply can't find "Advertiser.hpp" when included inside code.

Inside my main.cpp in "NewPackage" I have:

#include "Advertiser.hpp"

And the compiler fails on this one, with the output:

/home/casper/ros_workspace/MobileManipulator/hardware_reconfig_system/DeviceEmulators/src/GripperEmulator.cpp:26:26: fatal error: Advertiser.hpp: No such file or directory

The DeviceHandler package both builds the library + an executable, but is that the problem?

Also, should I do anything in the CMakeList.txt of "NewPackage" in order to link the library?

I have been searching for a couple of hours for an answer and nothing really seemed to do the trick. Hoping that it is just some detail I'm missing, any help is much appreciated.

Thanks /Casper

edit retag flag offensive close merge delete

Comments

Copy the compile errors that you get in your question and also add the code that doesn't compile.

dornhege gravatar imagedornhege ( 2013-10-04 03:31:27 -0600 )edit

Hi, sure, that should be in there now...

cschou gravatar imagecschou ( 2013-10-04 03:36:15 -0600 )edit

And where is the file in the package?

dornhege gravatar imagedornhege ( 2013-10-04 03:50:10 -0600 )edit

Well, the Advertiser.hpp is not in the "NewPackage". Is is in the shared object "libAdvertiser.so" created by the "DeviceHandler" package. So, the Advertiser.hpp is in /DeviceHandler/src/Advertiser.hpp.. Shouldn't I be able to access the headerfile used in a shared object? I should note, that this library stuff is a bit new to me...

cschou gravatar imagecschou ( 2013-10-04 04:06:55 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-10-04 04:39:41 -0600

dornhege gravatar image

Headers are not in the library at all. You need to provide them to the compiler. You add a bunch of -I include flags in you cpp export, but not one pointing to src, where your header lies. Either add that additional export or follow the standard ros way and move the header file to include/Advertiser in your package.

Your and client code should include that as #include "Advertiser/Advertiser.hpp. You'd probably also be able to remove a lot of the include exports.

edit flag offensive delete link more

Comments

Perfect!. I don't know why I didn't think of that. Sometimes you can really get so focused at a problem that you really miss the obvious. But your answer was spot on, I just moved the header file to the include folder and it works. Thank you for your help.

cschou gravatar imagecschou ( 2013-10-04 09:00:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-10-04 02:39:44 -0600

Seen: 118 times

Last updated: Oct 04 '13