Ask Your Question
1

Finding necessary components from the include statements

asked 2018-03-12 17:39:23 -0500

hagm gravatar image

updated 2018-03-12 17:41:29 -0500

I am reading this . In order to make a perfect CMakeLists.txt file, we have to supply all the necessary components inside the find_package function.

In general, after executing catkin_create_pkg, the default CMakeLists file comes with no components and we have to include based on our requirements.

Suppose I am using C++, then I have to include roscpp as component inside find. Now if I want to run the new C++ codes for which components I don't know, should I have to guess components form #include statements of cpp file?

For a given #include statement (say #include "boost/bind.hpp"), how to find its components? Is there any way to get all components required by my C++ file without explicitly specifying?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-12 20:40:56 -0500

JamesGiller gravatar image

Hi,

I hope I can help you to create CMakeLists.txt files for your ROS projects. Please let me know if I miss some information you are looking for.

Firstly, you can specify dependencies when you call catkin_create_pkg on the command line so that not only will the components be automatically included in the find_package call but the file package.xml will also be updated correctly. If you want to create a new package based on C++, then enter catkin_create_pkg <your new package name> roscpp on the command line and roscpp will be included in find_package automatically. A number of other packages can also be listed at the end of catkin_create_pkg, separated by spaces, to include them too. If you want to also include compiled Boost libraries such as filesystem, then you enter catkin_create_pkg -b filesystem<your new package name> roscpp on the command line.

Now if I want to run the new C++ codes for which components I don't know, should I have to guess components form #include statements of cpp file?

If you are creating your own ROS project from scratch, you should know which libraries you will be using, but you may not know the CMake components, of which there could be many. When you're going to be using MoveIt, your project will depend on the moveit_core, moveit_msgs, and moveit_ros_planning_interface components. You can see all the components for major ROS libraries at the top of their wiki page as links separated by |. Each component will have its own sub-dependencies too. If you are using someone else's code in your project, you may have to look inside the #include statements they use to know which libraries you will depend on; however, the original author should also provide a list of dependencies on GitHub or wherever the code was shared.

Unfortunately, I don't know of any tool that will scan #include statements in C++ files to determine appropriate catkin components. I think it would definitely be possible to make such a tool though, and it would be useful!

Finally, you don't have to worry about including certain components, especially Boost libraries like bind, explicitly in your CMakeLists.txt because they are most likely included automatically when you specify other components like roscpp. I usually add all the components I think I will need to find_package then build and see if any errors appear, which will let me know I am still missing a component.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-03-12 17:39:23 -0500

Seen: 35 times

Last updated: Mar 12 '18