I'm having trouble linking my Drake build to a ROS2 project. I'm pretty new to bazel and cmake, so I apologize for this potentially basic question.
Hardware
Raspberry Pi 5 running Ubuntu 24.04. I needed to build Drake since RPi is arm64.
Setup
I was able to successfully build Drake by...
build --define NO_DREAL=ON
and build --jobs=1
to the .bazelrc
filelibquadmath0
from packages_noble.txt
bazel build //tools/install/libdrake:libdrake.so
Problem
Now, I am struggling to get it working with a ROS2 control project. I looked through the external drake examples, but can't find one that seems to match my situation (the cmake examples seem to also have had the drake library built with cmake, not bazel). If I want to use Drake with a ROS project that uses CMake, does that mean I need to also build Drake with CMake?
Things I've tried
CMakeLists.txt
file within the ROS2 package.
set(drake_DIR /home/louis/drake/tools/install/libdrake)
set(drake_DIR /home/louis/drake/bazel-drake/tools/install/libdrake)
list(APPEND CMAKE_PREFIX_PATH /home/louis/drake/tools/install)
list(APPEND CMAKE_PREFIX_PATH /home/louis/drake/tools/install/libdrake/)
list(APPEND CMAKE_PREFIX_PATH /home/louis/drake)
find_package(drake REQUIRED)
target_link_libraries(my_ros2_package_name PUBLIC drake::drake)
.in
suffix from the drake-config.cmake.in
file in drake/tools/install/libdrake
... just to see if colcon build
would recognize the file, and it did, but then I get a similar error with lcm-config.cmake
. I'm sure this isn't the correct way to solve this, but incase it is helpful to know that it seems to be able to find drake-config.cmake
after doing this. The BUILD.bazel
file seems to have a command called drake_config_cmake_expand
to turn the .cmake.in
file into a .cmake
file, but I don't see this resulting file after the bazel build.Bazel Build Output
INFO: Found 1 target...
Target //tools/install/libdrake:libdrake.so up-to-date:
bazel-bin/tools/install/libdrake/libdrake.so
INFO: Elapsed time: 17295.341s, Critical Path: 156.09s
INFO: 8175 processes: 4062 internal, 4113 processwrapper-sandbox.
INFO: Build completed successfully, 8175 total actions
Error Message on colcon build
of the ROS2 package
By not providing "Finddrake.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "drake", but
CMake did not find one.
Could not find a package configuration file provided by "drake" with any of
the following names:
drakeConfig.cmake
drake-config.cmake
Add the installation prefix of "drake" to CMAKE_PREFIX_PATH or set
"drake_DIR" to a directory containing one of the above files. If "drake"
provides a separate development package or SDK, be sure it has been
installed.
Resources I used
If I want to use Drake with a ROS project that uses CMake, does that mean I need to also build Drake with CMake?
Yes. (Using downloaded Drake binaries would also work, but as you correctly note there are no binaries published for arm64 at the moment.) If everything in your ecosystem is Bazel, then you can consume Drake as a Bazel external, but for any other situation you should be using the CMake interface to build and install Drake in a way that's compatible with standard build and packaging conventions.
See drake_cmake_external for the most relevant example. It uses CMake to fetch Drake source code, compile it, install it, and then depend on it from your own code. It doesn't show any details specific to colcon, but hopefully those aren't very difficult once the general CMake machinery is working correctly.
The example defaults to building eigen & fmt & spdlog from source, with comments saying how to use the operating system version instead. For ROS2 compatibility, the OS versions are probably strictly required, so the three WITH_USER_...
settings should be OFF
and also remove the ExternalProject_Add(...)
code for those three dependencies.
building drake with
bazel build //tools/install/libdrake:libdrake.so
This only builds some parts, and doesn't actually install anything (which using with ROS2 would require).
Or instead, if you're just trying to get the thing working by hand (without trying to use extra layers of automation), then the boring thing would probably also just work fine:
git clone --filter=blob:none https://github.com/RobotLocomotion/drake.git
mkdir drake-build
cd drake-build
cmake ../drake -DCMAKE_PREFIX_PATH=/the/destination/you/want
make install