Ask Your Question
0

adding support lib and headers to ros package

asked 2011-08-10 01:23:04 -0500

cmsoda gravatar image

Hi all, I want to create a support class for my ros package. Let's say I want to create a class which represent a database table. This class is used by many services in my package. Where should I put the header (support.h) file and the support.cpp files? If I add them under src when I compile the class cannot be found also I tried to add under cmakelists file but without success. Can someone help me? Best Regads

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2011-08-10 01:32:36 -0500

dornhege gravatar image

updated 2011-08-11 04:21:05 -0500

You are naming three totally different things with "putting". A class cannot be used by a service (if you mean a ROS service), you need to provide a service server implementation.

Regarding "putting" in the sense of file location: If other packages besides the one you are implementing are using the class it is good practice to put the header in include/mypackage/header.h, and include the file in your sources via #include "mypackage/header.h". In that case you should also take care of exporting c++ directives in the manifest.

If the header file is only used in the package you can put it in src/.

The .cpp files usually go in src/.

Regarding CMake, in most cases you don't need to put the headers in there. If you create a new package the CMakeLists.txt already contains the commands for creating a library and exectable, you just need to uncomment them.

Can you be more precise on what exactly you are doing, give a minimal example and say what doesn't work (i.e. what means "cannot use it" for you, give the error messages)? Are you working in the same package or are you building a library package that you want to use in other packages? In the second case you need the export line in the manifest, but the term "-lros" is the linker directive for this package, i.e. instead of "-lros" it should be "-lmylib".

If class.h and class.cpp are in src/ and you have another source file in src/ you should be able to include and use class.h without a problem. If class.h is in include/mypackage/class.h, you should include that file using #include "mypackage/class.h".

edit flag offensive delete link more
0

answered 2011-08-11 02:55:29 -0500

cmsoda gravatar image

I added my class.h and class.cpp under src folder but when I compile I cannot use this inside another class that implement a services of the package. Also if I add the class.h I see error such as 'int not a know type'. Maybe I am not configuring correctly my manifest.xml. I added this. I also placing class.h under include/mypackage doesn't change.

<cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -Wl,-rpath,${prefix}/lib -lros"/>

edit flag offensive delete link more

Comments

You can update your original question by editing.
dornhege gravatar imagedornhege ( 2011-08-11 04:06:16 -0500 )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: 2011-08-10 01:23:04 -0500

Seen: 1,108 times

Last updated: Aug 11 '11