# Using Conan in ROS2 Package

**URL:** <https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157>\
**Category:** ROS General\
**Tags:** conan\
**Created:** [June 23, 2022, 5:49am UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157 "2022-06-23T05:49:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenrui03071117](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@chenrui03071117](https://discourse.openrobotics.org/u/chenrui03071117)\
**Post date:** [June 23, 2022, 5:49am UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/1 "2022-06-23T05:49:47Z")

</div>

Hi everyone!  
I used conan to manipulate dependencies in ros2 package developmen, but I ran in some troubles:

1. Header files. Suppose I use conan package (such as glog, gflags) in A package, and B depends on A, then awful thing happens, I can’t acquire those conan packages’s header files path in B.
2. Libraries. Like above, I have to source activated\_run.sh in A before building B package.  
Is there solution in ament\_cmake to solve these?

---

<div class="post-metadata">

**Author:** ![mattiasmar](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mattiasmar/32/17263_2.png) [@mattiasmar](https://discourse.openrobotics.org/u/mattiasmar)\
**Post date:** [April 24, 2023, 11:39am UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/2 "2023-04-24T11:39:16Z")

</div>

Any insights to this problem?

---

<div class="post-metadata">

**Author:** ![danimtb](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/danimtb/32/23585_2.png) [@danimtb](https://discourse.openrobotics.org/u/danimtb)\
**Post date:** [December 2, 2024, 3:07pm UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/3 "2024-12-02T15:07:44Z")

</div>

Hi!

The way to propagate headers of Conan generated CMake targets is using the ament helper `ament_target_dependencies()`. That way, the Conan packages are treated as a ROS package target and linked in the same way:

```auto
ament_target_dependencies(${TARGET_NAME} rclcpp <conan-require-name>)

```

We have recently released a new integration for using Conan packages in ROS, so you’d like to check it out (it talks about the management of Conan packages as transitive dependencies as well): [Enhancing ROS robotics development with C/C++ Conan packages](https://blog.conan.io/2024/11/28/Enhancing-ros-builds-with-Conan.html)

---

<div class="post-metadata">

**Author:** ![peci1](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/peci1/32/10145_2.png) [@peci1](https://discourse.openrobotics.org/u/peci1)\
**Post date:** [December 2, 2024, 9:35pm UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/4 "2024-12-02T21:35:18Z")

</div>

Hmm, without a package.xml in the conan dependencies, how do you prevent rosdep from installing (or at least trying to) the system apt packages? How do you intend to let rosdep know this dependency is handled by conan?

---

<div class="post-metadata">

**Author:** ![traversaro](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/traversaro/32/28_2.png) [@traversaro](https://discourse.openrobotics.org/u/traversaro)\
**Post date:** [December 4, 2024, 10:07am UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/5 "2024-12-04T10:07:17Z")

</div>

This is interesting, thanks for sharing!

From what I understand, ROS 2 packages are still managed via apt, so how do you ensure that there are no ABI conflicts from packages that are installed from apt as dependencies of ROS 2 packages, and packages that are installed by conan, as `fmt` in the example, that if I recall correctly is also a ROS transitive dependency via spdlog?

---

<div class="post-metadata">

**Author:** ![danimtb](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/danimtb/32/23585_2.png) [@danimtb](https://discourse.openrobotics.org/u/danimtb)\
**Post date:** [December 17, 2024, 11:50am UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/6 "2024-12-17T11:50:05Z")

</div>

yes, that’s true.

The aim of the integration is to provide the ROS developers with an alternative and to be able to consume the conan packages easily. Of course, there could be conflicts or redundant dependencies between rosdep and conan, however, we do not envision conan as replacement of rosdep/apt, but as a complement to incorporate new libraries to ROS packages in an easy workflow.

---

<div class="post-metadata">

**Author:** ![danimtb](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/danimtb/32/23585_2.png) [@danimtb](https://discourse.openrobotics.org/u/danimtb)\
**Post date:** [December 17, 2024, 12:05pm UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/7 "2024-12-17T12:05:17Z")

</div>

we did some tests with rosdep writing a Conan component to let rosdep install Conan packages and it worked well with some small caveats but it could be done as a complement to the ROSEnv generator.

However, first, we had to add the ROSEnv generator as a way to activate the build environment for Colcon to recognize the Conan installed dependencies.

If the rosdep integration part is something that could be useful please let us know, we are willing to streamline the integration for ROS users. Thank you!

---

<div class="post-metadata">

**Author:** ![ZhenshengLee](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/zhenshenglee/32/10103_2.png) [@ZhenshengLee](https://discourse.openrobotics.org/u/ZhenshengLee)\
**Post date:** [December 18, 2024, 8:35am UTC](https://discourse.openrobotics.org/t/using-conan-in-ros2-package/26157/8 "2024-12-18T08:35:06Z")

</div>

I think this would help, [ROS 2 Conan Integration - Next Generation ROS - ROS Discourse](http://discourse.ros.org/t/ros-2-conan-integration/20846)
