资讯

Bringing ROS into your native C/C++ workflow with Conan

ROS Discourse·2026/8/27 15:11:21🔗 原文

📌 概要

<p>Hi ROS community!</p> <p>I am Dani, a member of the <a href="https://conan.io" rel="noopener nofollow ugc">Conan C/C++ Package Manager</a> team, and we would like to introduce <a href="https://gith

<p>Hi ROS community!</p> <p>I am Dani, a member of the <a href="https://conan.io" rel="noopener nofollow ugc">Conan C/C++ Package Manager</a> team, and we would like to introduce <a href="https://github.com/conan-io/ros-conan" rel="noopener nofollow ugc">conan-io/ros-conan</a>: a collection of Conan recipes for installing and consuming ROS Kilted on Linux, macOS, and Windows.</p> <p>We have recently been working to offer an alternative workflow for C++ developers: install ROS with Conan, declare it in a conanfile, and consume its libraries like any other C++ package.</p> <p>Here is a quick demo of how it works:</p> <video controls="" width="100%"> <source src="https://github.com/conan-io/ros-conan/raw/refs/heads/danimtb/video/examples/pose_estimation/assets/ros-conan-screencast.mp4" type="video/mp4" /> </video> <p>This <a href="https://github.com/conan-io/ros-conan/tree/main/examples/pose_estimation" rel="noopener nofollow ugc">example</a> demonstrates how to install ROS Kilted along with OpenCV and TensorFlow to create a ROS node application that tracks the human pose from an image input.</p> <h1><a class="anchor" href="https://discourse.openrobotics.org#p-117322-lets-try-it-1" name="p-117322-lets-try-it-1"></a>Let’s try it!</h1> <p>Here is a small guide on how to start using ROS with Conan:</p> <h2><a class="anchor" href="https://discourse.openrobotics.org#p-117322-prepare-conan-and-the-ros-recipes-2" name="p-117322-prepare-conan-and-the-ros-recipes-2"></a>Prepare Conan and the ROS recipes</h2> <p>ROS 2 Kilted targets Python 3.12. Create a virtual environment and install Conan.</p> <p>On Linux or macOS:</p> <pre><code class="lang-bash">python3.12 -m venv .venv source .venv/bin/activate python -m pip install conan conan profile detect --force </code></pre> <p>On Windows PowerShell:</p> <pre><code class="lang-powershell">py -3.12 -m venv .venv .venv\Scripts\activate python -m pip install conan conan profile detect --force </code></pre> <p>Next, clone the recipes and add the repository as a local recipe index:</p> <pre><code class="lang-bash">git clone https://github.com/conan-io/ros-conan.git conan remote add ros-conan ./ros-conan --type=local-recipes-index </code></pre> <p>The recipe provides <code>core</code>, <code>base</code>, and <code>desktop</code> variants, allowing a project to select the part of the ROS distribution it needs.</p> <h2><a class="anchor" href="https://discourse.openrobotics.org#p-117322-start-with-a-ros-node-in-plain-cmake-3" name="p-117322-start-with-a-ros-node-in-plain-cmake-3"></a>Start with a ROS node in plain CMake</h2> <p>The clearest way to show the proposed workflow is a minimal C++ ROS node.</p> <pre><code class="lang-bash">cd ros-conan/examples/consumer_cmake </code></pre> <p>The complete dependency declaration is in the <code>conanfile.txt</code>:</p> <pre><code class="lang-ini">[requires] ros-kilted/2026.06.17 [generators] CMakeToolchain CMakeDeps [layout] cmake_layout </code></pre> <p>The CMake side uses the standard package config and imported target provided by <code>rclcpp</code>:</p> <pre><code class="lang-cmake">cmake_minimum_required(VERSION 3.22) project(conan_ros2_kilted_consumer CXX) find_package(rclcpp REQUIRED) add_executable(consumer_node src/main.cpp) target_link_libraries(consumer_node PRIVATE rclcpp::rclcpp) </code></pre> <p>From the example directory, install the dependencies:</p> <pre><code class="lang-bash">conan install --profile=../../profiles/ros --build=missing </code></pre> <p>This command builds ROS and any missing dependencies from source if the binaries are not already cached. The first run can take a while, but the resulting packages are cached for reuse.</p> <p>Now build the application with the same commands used by any other CMake project:</p> <pre><code class="lang-bash"># macOS and Linux cmake --preset conan-release cmake --build --preset conan-release # Windows cmake --preset conan-default cmake --build --preset conan-release </code></pre> <p>Activate the environment:</p> <pre><code class="lang-bash"># macOS and Linux /build/generators/conanrun.sh # Windows .\build\generators\conanrun.bat </code></pre> <p>And run the node:</p> <pre><code class="lang-bash"># macOS and Linux ./build/Release/consumer_node # Windows .\build\Release\consumer_node.exe [INFO] [...] [conan_test_package_node]: Conan consumer_node: rclcpp linked and node started. </code></pre> <p>There is no ROS-specific project layout, <code>package.xml</code>, <code>ament_cmake</code> integration, or <code>colcon</code> workspace in this example.</p> <p><strong>An existing CMake application can add ROS without adopting a separate development flow</strong>, while Conan manages ROS and the application’s other C++ dependencies together.</p> <p>As an alternative, for projects using a colcon workspace, the <a href="https://github.com/conan-io/ros-conan/tree/main/examples/consumer_colcon" rel="noopener nofollow ugc">colcon example</a> shows the same Conan-provided ROS installation being consumed by ordinary <code>ament_cmake</code> packages. Teams can choose the development model that fits each project.</p> <h2><a class="anchor" href="https://discourse.openrobotics.org#p-117322-run-a-familiar-ros-tutorial-4" name="p-117322-run-a-familiar-ros-tutorial-4"></a>Run a familiar ROS tutorial</h2> <p>The packaged ROS installation also supports the usual ROS commands. Let’s use the <code>desktop</code> variant to run the <a href="https://docs.ros.org/en/kilted/Tutorials/Beginner-CLI-Tools/Introducing-Turtlesim/Introducing-Turtlesim.html">turtlesim tutorial</a>.</p> <pre><code class="lang-bash">cd ros-conan/examples/consumer_cmake </code></pre> <p>First of, <strong>update the conanfile.txt</strong> to indicate the <strong>desktop variant</strong> for this case (as this is the one that includes the <code>turtlesim</code> package):</p> <pre><code class="lang-ini">[requires] ros-kilted/2026.06.17 [options] ros-kilted/*:variant=desktop </code></pre> <p>Use the install command to install and build the packages as we did previously (<strong>this will take some time</strong> as the desktop variant includes many more packages of ROS):</p> <pre><code class="lang-bash">conan install --profile=../../profiles/ros --build=missing </code></pre> <p>Activate the generated run environment and launch <code>turtlesim</code> as described in the ROS tutorials:</p> <pre><code class="lang-bash"># Linux and macOS source conanrun.sh ros2 run turtlesim turtlesim_node </code></pre> <pre><code class="lang-bat">REM Windows conanrun.bat ros2 run turtlesim turtlesim_node </code></pre> <p>In a second terminal, launch the keyboard controller. You can use <code>conan run</code> command to launch the command inside the enviroment directly:</p> <pre><code class="lang-bash">conan run "ros2 run turtlesim turtle_teleop_key" --profile=ros-conan/profiles/ros </code></pre> <p>The <strong>ROS commands and behavior are unchanged</strong>, Conan supplies the installation and runtime environment.</p> <h2><a class="anchor" href="https://discourse.openrobotics.org#p-117322-why-consume-ros-with-conan-5" name="p-117322-why-consume-ros-with-conan-5"></a>Why consume ROS with Conan?</h2> <p>Bringing ROS into the Conan dependency graph offers several advantages:</p> <ul> <li> <p><strong>A native C++ workflow:</strong> plain CMake projects can use <code>find_package(rclcpp REQUIRED)</code> and link to <code>rclcpp::rclcpp</code>. They do not need a <code>colcon</code> workspace or <code>ament_cmake</code>.</p> </li> <li> <p><strong>The same workflow as any other C/C++ package:</strong> declare ROS in a <code>conanfile</code> and use the same install command, profiles, options, lockfiles, and local cache across Linux, macOS, and Windows.</p> </li> <li> <p><strong>One dependency graph for the whole application:</strong> Conan detects version conflicts and lets ROS compose directly with libraries from <a href="https://conan.io/center" rel="noopener nofollow ugc">ConanCenter (the Conan central repository for open-source libraries)</a>, such as OpenCV, Eigen, or TensorFlow Lite.</p> </li> <li> <p><strong>Per-project ROS dependency:</strong> Different ROS versions and distributions could coexist in the Conan cache on the same machine. Each project would select and activate its own ROS dependency without colliding with a system-wide installation.</p> </li> </ul> <h2><a class="anchor" href="https://discourse.openrobotics.org#p-117322-we-would-like-your-feedback-6" name="p-117322-we-would-like-your-feedback-6"></a>We would like your feedback</h2> <p>ROS 2 Kilted is the first distribution covered by these recipes. The <code>core</code> and <code>desktop</code> variants are exercised in CI by building from source for Linux (gcc 13, X86_64/ARM64), macOS (clang 17, x86_64/ARM64), and Windows (MSVC 19.40).</p> <p>We would particularly like to hear:</p> <ul> <li> <p>How does the proposed native C/C++ workflow compare with the traditional ROS development workflow for your projects?</p> </li> <li> <p>Would per-project ROS dependencies help you develop and test packages against multiple ROS versions or distributions?</p> </li> <li> <p>Which third-party C or C++ packages would you want to combine with ROS through the same <code>conanfile</code>?</p> </li> <li> <p>Which ROS distributions, package variants, and platforms should we prioritize next?</p> </li> </ul> <p>Please try the <a href="https://github.com/conan-io/ros-conan" rel="noopener nofollow ugc">quick start and examples</a> and share your experience in this thread. Bugs and contributions are also welcome in the repository’s <a href="https://github.com/conan-io/ros-conan/issues" rel="noopener nofollow ugc">issues</a> and pull requests.</p> <hr /> <p><strong>We will be at ROSCon Global 2026 in Toronto</strong>, so if you are attending, we would be very happy to discuss this workflow and your feedback in person.</p> <p>Thanks for taking a look. We are looking forward to hearing what you think!</p> <p><small>1 post - 1 participant</small></p> <p><a href="https://discourse.openrobotics.org/t/bringing-ros-into-your-native-c-c-workflow-with-conan/57697">Read full topic</a></p>