Example showing how a colcon workspace can pick up
ros-kilted from Conan as if it were a system-installed ROS distribution. Two ROS packages
are built side-by-side:
dummy_lib— a plainament_cmakestatic library with no ROS dependencies, used to demonstrate cross-package linking inside the workspace.consumer_node— depends ondummy_libandrclcpp, prints a message and starts a short-lived node.
conanfile.txt requires ros-kilted/2026.06.17 and pulls in the generators
that make colcon discover ROS 2:
| Generator | Role |
|---|---|
CMakeToolchain |
Produces conan_toolchain.cmake — pinned compiler/std/runtime for every CMake project. |
CMakeDeps |
Generates <Pkg>-config.cmake for every Conan dependency, so find_package just works. |
VCVars |
Sets up the MSVC environment on Windows. |
ROSEnv |
Generates conanrosenv.{bat,sh} — exposes AMENT_PREFIX_PATH, CMAKE_PREFIX_PATH, PYTHONPATH, and the ROS install/runtime so colcon finds messages, Python tooling and runtime libraries. |
-
A C++17 compiler.
-
CMake ≥ 3.22 (the profile tool-requires
cmake/3.29.3). -
colconandcatkin_pkgavailable onPATH:python -m pip install --upgrade colcon-common-extensions catkin_pkg
On macOS, make sure the
pythonthat runscolconis the same one thatament_cmakepicks up viafind_package(Python3)— different Python versions onPATHcausecatkin_pkgto land in the wrongsite-packages. The CI example pins this explicitly with-DPython3_EXECUTABLE=....
From this directory:
conan install . --profile=../../profiles/ros --build=missingActivate the Conan-generated ROS environment and let colcon drive the rest:
Windows (cmd):
call build\generators\conanrosenv.bat
colcon build --event-handlers console_cohesion+
call install\setup.bat
ros2 run consumer_node consumer_nodemacOS / Linux (bash/zsh):
. ./build/Release/generators/conanrosenv.sh
colcon build --event-handlers console_cohesion+
. ./install/setup.sh
ros2 run consumer_node consumer_noderos2 itself is shipped by ros-kilted (Scripts/ros2.exe on Windows, bin/ros2 on
macOS/Linux) and conanrosenv.{bat,sh} puts it on PATH together with the
AMENT_PREFIX_PATH / PYTHONPATH entries it needs. Sourcing the workspace's
install/setup.{bat,sh} then prepends the freshly built consumer_node to that
AMENT_PREFIX_PATH, so ros2 run (or any other ros2 subcommand) resolves it like
on a system-installed ROS 2.
If you prefer to skip ros2, the executable is also reachable directly from the
install tree:
install\consumer_node\lib\consumer_node\consumer_node.exe./install/consumer_node/lib/consumer_node/consumer_nodeExpected output (truncated):
[dummy_lib] hello from library
[INFO] [...] [colcon_consumer_node]: colcon consumer_node: rclcpp linked and node started.
The exact CI invocation (with the Python-interpreter pinning mentioned above) lives in
ci_test_example.py.