ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Get path to built files programmatically

asked 2017-02-10 07:49:15 -0600

lucasw gravatar image

updated 2020-11-21 12:12:55 -0600

I have add_custom_commands to build files that will be loaded at run time by a ros node. Right now those files get put into build/my_package/. Is there a combination of a destination to provide cmake and something like ros::package::getPath() that will allow me to load the files regardless of whether using catkin_make install or devel.

The solution I don't want is to build the files into the source directory.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-02-10 22:29:28 -0600

lucasw gravatar image

updated 2017-02-10 22:34:23 -0600

A solution that doesn't involve build artifacts in the source tree could be to turn the generated files into a library or add it to the executable- convert the binary files into header files like

xxd -i my_cmake_generated_file.bin > my_cmake_generated_file.h

Which produces:

unsigned char my_cmake_generated_file[] = {
0x46, 0x53, 0x48, 0x04, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x44, 0x00,
  0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00
unsigned int my_cmake_generated_file_len = 83;

And then code that loads a binary into a byte array could be simplified to just use this from the header file directly

edit flag offensive delete link more

answered 2017-02-10 10:11:11 -0600

joq gravatar image

You probably just need to install the built files:


After that, I think getPath() should find them (not tested).

edit flag offensive delete link more

Comments makes it sound like I should just have a build folder in my source tree and have git ignore it.

lucasw gravatar image lucasw  ( 2017-02-10 21:54:45 -0600 )edit

I don't think that is what they were talking about. They were talking about how to address downloaded test files. See:

joq gravatar image joq  ( 2017-02-11 11:35:33 -0600 )edit

The downloading of test files doesn't seem that different, is almost the same case- there are files that need to be found at run time but getPath will point to the source package location when doing a non-install catkin_make.

lucasw gravatar image lucasw  ( 2017-02-14 05:52:17 -0600 )edit

Another solution that comes to mind is to bake the build location into the executable though cmake.

lucasw gravatar image lucasw  ( 2017-02-14 05:54:46 -0600 )edit

Also from it sounds like roslaunch <param name="file_dir" value="$(find my_package)/... will point to a share directory, but like the other comments linked to I wish I could use catkin_find through a C++ api.

lucasw gravatar image lucasw  ( 2017-02-14 06:02:12 -0600 )edit

Question Tools



Asked: 2017-02-10 07:49:15 -0600

Seen: 529 times

Last updated: Feb 10 '17