Rosanswers logo

How can I control which include paths will be used when colcon builds a package? I would like to use the includes form a package in my current workspace instead of the ones of the same package in the ros2 underlay workspace. It seems to look in both places, but unfortunately the underlay workspace has priority.

As a concrete example, I'm trying to build the master branch of rosbag2. I am using the latest foxy (patch1) binary release. The build currently fails because it is trying to use the rosbag2_cpp include files from the foxy release when building the rosbag_transport package. Instead it should be looking for the rosbag2_cpp includes in the current workspace. (the max_bagfile_size has been added in rosbag2_cpp/storage_options.hpp on master (current workspace) but it is not present in the foxy release, see error below) I solved the build errors by simply deleting the rosbag2 library out of the ros2 binary installation so that the includes from the current workspace are used. However I am thinking there must be a better way to do this.

Sourcing ros2 environment, then creating a workspace and cloning rosbag2 into it, running colcon build:

--- stderr: rosbag2_transport
/home/pi/ws/src/rosbag2/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp: In function ‘PyObject* rosbag2_transport_record(PyObject*, PyObject*, PyObject*)’:
/home/pi/ws/src/rosbag2/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp:149:19: error: ‘using StorageOptions = struct rosbag2_cpp::StorageOptions’ {aka ‘struct rosbag2_cpp::StorageOptions’} has no member named ‘max_bagfile_duration’; did you mean ‘max_bagfile_size’?
  149 |   storage_options.max_bagfile_duration = static_cast<uint64_t>(max_bagfile_duration);
      |                   ^~~~~~~~~~~~~~~~~~~~
      |                   max_bagfile_size
make[2]: *** [CMakeFiles/rosbag2_transport_py.dir/build.make:66: CMakeFiles/rosbag2_transport_py.dir/src/rosbag2_transport/rosbag2_transport_python.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/rosbag2_transport_py.dir/all] Error 2
make: *** [Makefile:144: all] Error 2
Failed   <<< rosbag2_transport [32.6s, exited with code 2]

Edit: These are the compiler calls without --merge-install:

/usr/bin/c++  -DDEFAULT_RMW_IMPLEMENTATION=rmw_fastrtps_cpp -DPLUGINLIB__DISABLE_BOOST_FUNCTIONS -DROS_PACKAGE_NAME=\"rosbag2_transport\" -DSPDLOG_COMPILED_LIB -Drosbag2_transport_py_EXPORTS -I/usr/include/python3.8 -I/home/pi/ws/src/rosbag2/rosbag2_transport/include -isystem /home/pi/ws/install/rosbag2_compression/include -isystem /home/pi/ros2/opt/yaml_cpp_vendor/include -isystem /home/pi/ros2/include -isystem /home/pi/ws/install/rosbag2_storage/include -isystem /home/pi/ws/install/zstd_vendor/include -isystem /home/pi/ws/install/rosbag2_cpp/include -isystem /home/pi/ws/install/shared_queues_vendor/include/moodycamel -isystem /home/pi/ws/install/shared_queues_vendor/include  -fPIC   -Wall -Wextra -Wpedantic -Werror -std=gnu++14 -o CMakeFiles/rosbag2_transport_py.dir/src/rosbag2_transport/rosbag2_transport_python.cpp.o -c /home/pi/ws/src/rosbag2/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp

and with --merge-install:

/usr/bin/c++  -DDEFAULT_RMW_IMPLEMENTATION=rmw_fastrtps_cpp -DPLUGINLIB__DISABLE_BOOST_FUNCTIONS -DROS_PACKAGE_NAME=\"rosbag2_transport\" -DSPDLOG_COMPILED_LIB -Drosbag2_transport_py_EXPORTS -I/usr/include/python3.8 -I/home/pi/ws/src/rosbag2/rosbag2_transport/include -isystem /home/pi/ws/install/include -isystem /home/pi/ros2/opt/yaml_cpp_vendor/include -isystem /home/pi/ros2/include -isystem /home/pi/ws/install/include/moodycamel  -fPIC   -Wall -Wextra -Wpedantic -Werror -std=gnu++14 -o CMakeFiles/rosbag2_transport_py.dir/src/rosbag2_transport/rosbag2_transport_python.cpp.o -c /home/pi/ws/src/rosbag2/rosbag2_transport/src/rosbag2_transport/rosbag2_transport_python.cpp

Originally posted by patrick on ROS Answers with karma: 13 on 2020-07-29

Post score: 1

Original comments

Comment by Karsten on 2020-07-30:
I can reproduce this in a foxy container when building in isolation, which is colcon's default. My rosbag2 overlay workspace works just fine when compiling with colcon build --merge-install. At this point I honestly have no idea and I wonder if that's a problem with rosbag2 or something more fundamental.

Comment by patrick on 2020-07-31:
I can confirm that with --merge-install it compiles fine for me too.

Comment by patrick on 2020-07-31:
I posted the compiler calls, I don't see how the include sequence is generated from the CMakeLists.txt. I'm not familiar enough with the build system to know whether this is a colcon / ament / or rosbag2 issue.

Comment by Karsten on 2020-07-31:
There's an open issue for this already: https://github.com/ros2/rosbag2/issues/447 I suspect it has something to do when we switched to modern cmake targets in Foxy. I'd recommend watching the ticket for further updates.


1 Answer 1


Rosanswers logo

The package failed to declare target dependencies and as a result the include directories for that dependency in the overlay isn't being set. Since the (older) headers are found in the underlay it fails with the compiler error complaining that the new symbol doesn't exist.

Please see https://github.com/ros2/rosbag2/pull/479 for the fix.

Originally posted by Dirk Thomas with karma: 16276 on 2020-07-31

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by patrick on 2020-07-31:
Thank you!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.