Unknown CMake command "ament_target_dependencies" in ROS 2 Lyrical

ament_target_dependencies deprecated in Kilted, removed in Lyrical: fix “Unknown CMake command” with target_link_libraries on every ROS 2 distro

Short answer: ROS 2 Lyrical removed ament_target_dependencies(), so any CMakeLists.txt that still calls it stops with Unknown CMake command "ament_target_dependencies". Replace the call with target_link_libraries(<target> PUBLIC rclcpp::rclcpp ${std_msgs_TARGETS}), listing every dependency the old call had. That line built and ran on Humble, Jazzy, Kilted and Lyrical in my test, so you can switch now without breaking older distros.

Unknown CMake command "ament_target_dependencies" in ROS 2 Lyrical: the replacement that builds on every distro — measured results table
At a glance: the main measured table from this article. Full details below.

The error

Starting >>> my_pkg
--- stderr: my_pkg
CMake Error at CMakeLists.txt:13 (ament_target_dependencies):
  Unknown CMake command "ament_target_dependencies".

You’ll mostly hit this when following a course or tutorial written for Humble or Jazzy. Most of them use ament_target_dependencies.

What I ran

On 2026-10-26 I built the same minimal package in the official ros:humble-ros-base, ros:jazzy-ros-base, ros:kilted-ros-base and ros:lyrical-ros-base Docker images. The package is one C++ node that publishes a std_msgs/msg/String, so it depends on rclcpp and std_msgs. Each variant changes only the dependency line in CMakeLists.txt. “Builds” below means colcon build succeeded and the node ran.

Result matrix: ament_target_dependencies builds on Humble and Jazzy, is deprecated on Kilted and fails on Lyrical; target_link_libraries with rclcpp::rclcpp and std_msgs targets builds on all four
Same package, one CMake line changed per row.
Distro CMake ament_cmake ament_target_dependencies
Humble 3.22.1 1.3.14 Builds, no warning
Jazzy 3.28.3 2.5.6 Builds, no warning
Kilted 3.28.3 2.7.5 Builds with a deprecation warning
Lyrical 4.2.3 2.8.8 Unknown CMake command

The fix

Before:

find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

add_executable(my_node src/my_node.cpp)
ament_target_dependencies(my_node rclcpp std_msgs)

After:

find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

add_executable(my_node src/my_node.cpp)
target_link_libraries(my_node PUBLIC
  rclcpp::rclcpp
  ${std_msgs_TARGETS}
)

You don’t have to work out the replacement yourself. Kilted’s deprecation warning prints it for your exact call:

CMake Deprecation Warning at /opt/ros/kilted/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:87 (message):
  ament_target_dependencies() is deprecated. Use target_link_libraries() with
  modern CMake targets instead. Try replacing this call with:

  target_link_libraries(n PUBLIC
    ${std_msgs_TARGETS}
    rclcpp::rclcpp
  )

If you have a Kilted machine or container, build there once and copy the suggested lines. That’s the quickest way to convert a package with many calls.

Three ways the fix can still fail

1. You only replaced rclcpp

The answer usually posted for this error is target_link_libraries(my_node PUBLIC rclcpp::rclcpp). That works only when the node uses nothing but rclcpp. My node also includes a message header, and dropping std_msgs failed on all four distros:

fatal error: std_msgs/msg/string.hpp: No such file or directory

Every package that was in the old ament_target_dependencies call has to appear in target_link_libraries.

2. Mixing plain and PUBLIC signatures

target_link_libraries(my_node rclcpp::rclcpp)
target_link_libraries(my_node PUBLIC ${std_msgs_TARGETS})

This failed on all four distros:

CMake Error at CMakeLists.txt:8 (target_link_libraries):
  The plain signature for target_link_libraries has already been used with
  the target "n".  All uses of target_link_libraries with a target must be
  either all-keyword or all-plain.

Use PUBLIC (or PRIVATE) on every target_link_libraries call for a target, or on none of them. Old tutorials often have a plain target_link_libraries line further down, for example for a non-ROS library. Add the keyword there too.

3. Trying to bring the old command back

Lyrical still installs the ament_cmake_target_dependencies package directory. Adding find_package(ament_cmake_target_dependencies REQUIRED) before the old call did not restore it. The build still stopped with Unknown CMake command. Convert the call instead.

${std_msgs_TARGETS} or std_msgs::std_msgs?

Both built and ran on all four distros. ${std_msgs_TARGETS} is what Kilted’s warning suggests for message packages. For non-message libraries, use the package’s own namespaced target, as with rclcpp::rclcpp.

One more Lyrical warning

Lyrical ships CMake 4.2.3. With cmake_minimum_required(VERSION 3.8), a common value in older package templates, Lyrical printed Compatibility with CMake < 3.10 will be removed from a future version of CMake. It’s only a warning, but raising the line to VERSION 3.10 silenced it and still built on Humble’s CMake 3.22.

FAQ

Why do I get Unknown CMake command “ament_target_dependencies”?

ROS 2 Lyrical removed ament_target_dependencies(). Any CMakeLists.txt that still calls it stops with this error.

What do I replace ament_target_dependencies with?

Use target_link_libraries(my_node PUBLIC rclcpp::rclcpp ${std_msgs_TARGETS}), listing every dependency the old call had. That line built and ran on Humble, Jazzy, Kilted and Lyrical in my test.

Why do I get “std_msgs/msg/string.hpp: No such file or directory” after the fix?

You only replaced rclcpp. Every package that was in the old ament_target_dependencies call has to appear in target_link_libraries.

What does “must be either all-keyword or all-plain” mean?

You mixed plain and PUBLIC target_link_libraries calls for one target. Use PUBLIC (or PRIVATE) on every call for that target, or on none of them.

Can I bring ament_target_dependencies back on Lyrical?

Not in my test. Adding find_package(ament_cmake_target_dependencies REQUIRED) before the old call did not restore it, so convert the call instead.

Not tested

Library packages that export targets to other packages (ament_export_targets, ament_export_dependencies), Python packages, and distros older than Humble. If you’re converting a library, its downstream packages need the exported targets too. Check that a dependent package still builds after the change.

Build script and raw output: evidence folder. Question this answers: Cmake error: Unknown CMake command “ament_target_dependencies”. Related: colcon build memory and time by executor and MAKEFLAGS.