ros2 build_error ai_generated true

colcon build: CMake Error at CMakeLists.txt: find_package(ament_cmake) failed

ID: ros2/colcon-build-cmake-error

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

colcon build fails because ament_cmake is not found. ROS 2 environment is not sourced.

generic

Workarounds

  1. 95% success Source the ROS 2 installation before building
    source /opt/ros/humble/setup.bash && cd ~/ros2_ws && colcon build
  2. 90% success Install missing packages via apt
    sudo apt install ros-humble-ament-cmake
  3. 88% success Use rosdep to install all dependencies
    cd ~/ros2_ws && rosdep install --from-paths src --ignore-src -y

Dead Ends

Common approaches that don't work:

  1. Install ament_cmake via pip 90% fail

    ament_cmake is a CMake package, not Python; pip install does nothing useful

  2. Build ament_cmake from source in your workspace 80% fail

    ament_cmake is core ROS 2 infrastructure; building from source causes version conflicts