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 close merge delete

Sort by » oldest newest most voted

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".

more

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"/>

more

You can update your original question by editing.
( 2011-08-11 04:06:16 -0500 )edit