Unable to build ROS 2 workspace due to missing px4_msgs dependency

I am working on building a PX4-ROS2-Gazebo-YOLOv8 software stack from source. During this process, I am attempting to build a ROS 2 workspace as follows:

mkdir -p ./ws_sensor_combined/src/
cd ./ws_sensor_combined/src/
git clone https://github.com/PX4/px4_msgs.git
git clone https://github.com/PX4/px4_ros_com.git
cd ..
source /opt/ros/jazzy/setup.bash
colcon build

The issue arises during colcon build. Namely, the ‘px4_msgs’ package builds successfully but ‘px4_ros_com’ fails with this fatal error:

Starting >>> px4_ros_com — stderr: px4_ros_com /home/user/projects/ws_sensor_combined/src/px4_ros_com/src/examples/listeners/vehicle_gps_position_listener.cpp:41:10: fatal error: px4_msgs/msg/sensor_gps.hpp: No such file or directory 41 | #include <px4_msgs/msg/sensor_gps.hpp> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. gmake[2]: *** [CMakeFiles/vehicle_gps_position_listener.dir/build.make:76: CMakeFiles/vehicle_gps_position_listener.dir/src/examples/listeners/vehicle_gps_position_listener.cpp.o] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:202: CMakeFiles/vehicle_gps_position_listener.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs… gmake: *** [Makefile:146: all] Error 2 — Failed <<< px4_ros_com [6.98s, exited with code 2] Summary: 0 packages finished [7.05s] 1 package failed: px4_ros_com 1 package had stderr output: px4_ros_com

I’d appreciate any help tracking down why this error is happening despite ‘px4_msgs’ building successfully. Thank you!

px4_ros_com repo have not been actively been maintained for PX4 (and px4_msgs) main branch. Do you have a particular need for it? I strongly suggest you to try the ROS 2 PX4 Interface library instead: PX4 ROS 2 Interface Library | PX4 Guide (main)

Your build is failing because the msgs definitions inpx4_msgs changed but the examples in px4_ros_com were not updated: sensor_gps got replaced with sensor_gnss.

Would you happen to know what the last branch of the px4_msgsgit project was that is compatible with px4_ros_com? I am following a set of instructions to setup a particular PX4-ROS2-Gazebo-YOLOv8 stack, as outlined here, that relies on the build succeeding, but that fails to pin the respective branches.

the repo you linked does not target a specific PX4 release but seeing that the last commit was 8 months ago, I’d suggest you to try and use v1.17.0:
use v1.17.0 for PX4 and px4_msgs and main for px4_ros_com.

Anyway, in the repo px4_ros_com is just used to remotely control the drone from ROS 2. If you want to use a better technique please consider replacing it with GitHub - Auterion/px4-ros2-interface-lib: Library to interface with PX4 from a companion computer using ROS 2 · GitHub . If you do that you can use main everywhere

Benja’s explanation points to the core issue: this is a version-skew problem, not a failed px4_msgs build.

If you need to reproduce that third-party stack exactly, I would pin all three moving parts explicitly:

  • PX4 release/tag
  • px4_msgs release/tag
  • px4_ros_com commit

rather than relying on main.

For example, if v1.17.0 is the compatibility point you choose, record the exact commit SHA of px4_ros_com that builds successfully with it as well. That makes the environment reproducible and prevents the same breakage later if main changes again.

I would also capture the failing and working combinations in a small compatibility table, e.g.:

PX4 px4_msgs px4_ros_com Result
main main main fails: sensor_gps.hpp missing
v1.17.0 v1.17.0 main/known SHA test

If the goal is long-term maintenance rather than reproducing the existing tutorial, migrating to px4-ros2-interface-lib is the cleaner path, as Benja suggested.

For tutorials that depend on multiple repos, pinning exact refs in the install instructions is important; otherwise a working setup can silently become unreproducible.