Colcon build include path from overlay workspace
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
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.I can confirm that with
--merge-install
it compiles fine for me too.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.
There's an open issue for this already: https://github.com/ros2/rosbag2/issue... 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.