PX4 SITL 彻底清理并修复 Protobuf 问题

PX4 SITL 彻底清理并修复 Protobuf 问题

📌 适用于 ROS Noetic + PX4 SITL(Gazebo 11)环境

本教程适用于在编译 PX4 SITL 时遇到 Protobuf 版本冲突、CMake 找不到正确的 Protobuf 头文件或库、MAVROS 运行错误 等问题。我们将彻底清理旧的 Protobuf 版本重新安装 ROS Noetic 和 PX4,确保系统使用正确的 Protobuf 版本


🚀 1. 彻底移除所有 Protobuf 相关文件

由于手动安装的 Protobuf 可能与系统版本冲突,我们需要完全清除所有 Protobuf 相关的库、头文件和编译缓存。

1.1 移除系统安装的 Protobuf

首先,使用 apt-get purge 命令移除所有 Protobuf 相关的软件包:

sudo apt-get purge libprotobuf* protobuf*

1.2 移除手动安装的 Protobuf

如果曾经手动编译安装过 Protobuf,它的头文件可能仍然残留在 /usr/local/include/ 目录下。删除 Protobuf 相关的头文件:

sudo rm -rf /usr/local/include/google/protobuf/

⚠️ 注意:请确保没有其他软件依赖手动安装的 Protobuf,否则可能导致部分程序无法运行。


🛠 2. 重新安装 ROS Noetic

由于 ROS 依赖 Protobuf,我们需要重新安装完整的 ROS Noetic 桌面版,以确保所有库文件正确。

sudo apt-get install ros-noetic-desktop-full --reinstall

⚠️ 这个命令可能需要一定时间,因为 ROS Noetic 是一个较大的安装包。

安装完成后,执行以下命令加载 ROS 环境变量

source /opt/ros/noetic/setup.bash

如果你使用 zsh 作为默认 Shell,则需要运行:

source /opt/ros/noetic/setup.zsh

🔄 3. 彻底清理 PX4 仿真环境

由于之前的编译可能已经缓存了错误的 Protobuf 版本,我们需要彻底删除 PX4 的 build 目录和 Gazebo 编译缓存。

3.1 删除 PX4 的编译缓存

cd ~/PX4-Autopilot
rm -rf build

3.2 删除 Gazebo SITL 的编译缓存

rm -rf Tools/sitl_gazebo/build
rm -rf Tools/sitl_gazebo/CMakeCache.txt

📥 4. 重新编译 PX4 SITL

清理完成后,我们可以完整更新 PX4 代码仓库,然后重新编译 PX4 SITL。

4.1 进入 PX4 目录并更新代码

cd ~/PX4-Autopilot
git submodule update --init --recursive

bash /home/xxx/PX4-Autopilot/Tools/setup/ubuntu.sh
xxx是用户名

4.2 重新编译 PX4 SITL

make clean
make px4_sitl gazebo

这将从头开始重新构建 PX4 和 Gazebo 插件,确保所有依赖库都是正确的。


✅ 5. 运行 PX4 SITL

如果编译成功,现在可以尝试运行 PX4 SITL 了。

roslaunch px4 mavros_posix_sitl.launch

如果 ROS 找不到 mavros,可以执行以下命令安装:

sudo apt install ros-noetic-mavros ros-noetic-mavros-extras ros-noetic-geographic-msgs

然后,再次尝试运行:

roslaunch px4 mavros_posix_sitl.launch

📌 6. 可能的额外检查

如果仍然遇到 protobuf 相关的错误,可以执行以下命令检查 Protobuf 版本是否正确:

which protoc
protoc --version
ldconfig -p | grep protobuf

正确的输出应该是

  • which protoc/usr/bin/protoc
  • protoc --versionlibprotoc 3.x(如 3.6.1
  • ldconfig -p | grep protobuf → 只显示 /lib/x86_64-linux-gnu/libprotobuf.so.17,而不应该/usr/local/lib/ 相关的 Protobuf 版本。

如果 ldconfig -p | grep protobuf 仍然显示 /usr/local/lib/libprotobuf.so,则需要运行:

sudo rm -rf /usr/local/lib/libprotobuf*
sudo ldconfig

然后再次编译 PX4:

cd ~/PX4-Autopilot
make clean
make px4_sitl gazebo

🎯 结论

本教程提供了一套完整的步骤,帮助你彻底清除 Protobuf 冲突,并重新安装 PX4 SITL。如果你按照教程操作,PX4 和 Gazebo 应该可以正常运行

🚀 最终流程总结

  1. 彻底清理 Protobufapt-get purgerm -rf 删除 Protobuf 头文件)。
  2. 重新安装 ROS Noeticapt-get install ros-noetic-desktop-full --reinstall)。
  3. 清除 PX4 的编译缓存(删除 build 目录)。
  4. 更新 PX4 子模块git submodule update --init --recursive)。
  5. 重新编译 PX4 SITLmake clean && make px4_sitl gazebo)。
  6. 运行 PX4 仿真roslaunch px4 mavros_posix_sitl.launch)。

如果你在某一步遇到问题,欢迎留言,我会继续帮你排查!🔥🚀

lixing@lixing:~/PX4-Autopilot$ make px4_sitl gazebo [0/1072] git submodule src/drivers/gps/devices [10/1072] git submodule src/modules/mavlink/mavlink [12/1072] git submodule Tools/simulation/gazebo-classic/sitl_gazebo-classic [13/1072] git submodule src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client [18/1072] Performing configure step for 'sitl_gazebo-classic' -- install-prefix: /usr/local -- cmake build type: RelWithDebInfo -- Using C++17 standard -- ccache enabled (export CCACHE_DISABLE=1 to disable) -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.58") found components: system thread filesystem -- Found DART: /usr/include (Required is at least version "6.6") found components: dart -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.40.0") found components: thread system filesystem program_options regex iostreams date_time -- Looking for ignition-math6 -- found version 6.15.1 -- Searching for dependencies of ignition-math6 -- Looking for OGRE... -- Found Ogre Ghadamon (1.9.0) -- Looking for OGRE_Paging... -- Found OGRE_Paging: optimized;/usr/lib/x86_64-linux-gnu/libOgrePaging.so;debug;/usr/lib/x86_64-linux-gnu/libOgrePaging.so -- Looking for OGRE_Terrain... -- Found OGRE_Terrain: optimized;/usr/lib/x86_64-linux-gnu/libOgreTerrain.so;debug;/usr/lib/x86_64-linux-gnu/libOgreTerrain.so -- Looking for OGRE_Property... -- Found OGRE_Property: optimized;/usr/lib/x86_64-linux-gnu/libOgreProperty.so;debug;/usr/lib/x86_64-linux-gnu/libOgreProperty.so -- Looking for OGRE_RTShaderSystem... -- Found OGRE_RTShaderSystem: optimized;/usr/lib/x86_64-linux-gnu/libOgreRTShaderSystem.so;debug;/usr/lib/x86_64-linux-gnu/libOgreRTShaderSystem.so -- Looking for OGRE_Volume... -- Found OGRE_Volume: optimized;/usr/lib/x86_64-linux-gnu/libOgreVolume.so;debug;/usr/lib/x86_64-linux-gnu/libOgreVolume.so -- Looking for OGRE_Overlay... -- Found OGRE_Overlay: optimized;/usr/lib/x86_64-linux-gnu/libOgreOverlay.so;debug;/usr/lib/x86_64-linux-gnu/libOgreOverlay.so -- Looking for ignition-math6 -- found version 6.15.1 -- Looking for ignition-transport8 -- found version 8.5.0 -- Searching for dependencies of ignition-transport8 -- Config-file not installed for ZeroMQ -- checking for pkg-config -- Checking for module 'libzmq >= 4' -- Found libzmq , version 4.3.2 -- Checking for module 'uuid' -- Found uuid, version 2.34.0 -- Looking for ignition-msgs5 -- found version 5.11.0 -- Searching for dependencies of ignition-msgs5 -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread (found suitable version "3.6.1", minimum required is "3") -- Looking for ignition-math6 -- found version 6.15.1 -- Checking for module 'tinyxml2' -- Found tinyxml2, version 6.2.0 -- Looking for ignition-msgs5 -- found version 5.11.0 -- Looking for ignition-common3 -- found version 3.17.0 -- Searching for dependencies of ignition-common3 -- Looking for dlfcn.h - found -- Looking for libdl - found -- Searching for <ignition-common3> component [graphics] -- Looking for ignition-common3-graphics -- found version 3.17.0 -- Searching for dependencies of ignition-common3-graphics -- Looking for ignition-math6 -- found version 6.15.1 -- Looking for ignition-fuel_tools4 -- found version 4.9.1 -- Searching for dependencies of ignition-fuel_tools4 -- Checking for module 'jsoncpp' -- Found jsoncpp, version 1.7.4 -- Checking for module 'yaml-0.1' -- Found yaml-0.1, version 0.2.2 -- Checking for module 'libzip' -- Found libzip, version 1.5.1 -- Looking for ignition-common3 -- found version 3.17.0 -- Looking for ignition-math6 -- found version 6.15.1 -- Looking for ignition-msgs5 -- found version 5.11.0 -- Building klt_feature_tracker without catkin -- Building OpticalFlow with OpenCV -- catkin DISABLED -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread (found version "3.6.1") -- Gazebo version: 11.15 -- Found GStreamer: adding gst_camera_plugin -- Found GStreamer: adding gst_video_stream_widget -- Configuring done -- Generating done -- Build files have been written to: /home/lixing/PX4-Autopilot/build/px4_sitl_default/build_gazebo-classic [68/1072] Performing configure step for 'libmicroxrceddsclient_project' -- libmicroxrceddsclient_project configure command succeeded. See also /home/lixing/PX4-Autopilot/build/px4_sitl_default/src/modules/uxrce_dds_client/src/libmicroxrceddsclient_project-stamp/libmicroxrceddsclient_project-configure-*.log [69/1072] Performing build step for 'libmicroxrceddsclient_project' -- libmicroxrceddsclient_project build command succeeded. See also /home/lixing/PX4-Autopilot/build/px4_sitl_default/src/modules/uxrce_dds_client/src/libmicroxrceddsclient_project-stamp/libmicroxrceddsclient_project-build-*.log [70/1072] Performing install step for 'libmicroxrceddsclient_project' -- libmicroxrceddsclient_project install command succeeded. See also /home/lixing/PX4-Autopilot/build/px4_sitl_default/src/modules/uxrce_dds_client/src/libmicroxrceddsclient_project-stamp/libmicroxrceddsclient_project-install-*.log [884/1072] Performing build step for 'sitl_gazebo-classic' [38/115] Generating /home/lixing/PX4-A...dels/quadtailsitter/quadtailsitter.sdf /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/quadtailsitter/quadtailsitter.sdf.jinja -> /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/quadtailsitter/quadtailsitter.sdf [40/115] Generating /home/lixing/PX4-A..._gazebo-classic/models/plane/plane.sdf /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/plane/plane.sdf.jinja -> /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/plane/plane.sdf [46/115] Generating /home/lixing/PX4-A...ebo-classic/models/px4flow/px4flow.sdf /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/px4flow/px4flow.sdf.jinja -> /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/px4flow/px4flow.sdf [66/115] Building CXX object CMakeFile...ugin.dir/src/gazebo_aruco_plugin.cpp.o FAILED: CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o /usr/bin/ccache /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_TEST_DYN_LINK -DBOOST_THREAD_DYN_LINK -DLIBBULLET_VERSION=2.88 -DLIBBULLET_VERSION_GT_282 -Dgazebo_aruco_plugin_EXPORTS -I/home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/include -I. -I/usr/local/include/eigen3/eigen3 -I/usr/include/gazebo-11/gazebo/msgs -I/home/lixing/PX4-Autopilot/build/px4_sitl_default/mavlink -I/home/lixing/PX4-Autopilot/build/px4_sitl_default/mavlink/mavlink/v2.0 -I/usr/include/Paging -I/home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/external/OpticalFlow/include -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/gazebo-11 -isystem /usr/include/bullet -isystem /usr/include/simbody -isystem /usr/include/sdformat-9.10 -isystem /usr/include/ignition/math6 -isystem /usr/include/OGRE -isystem /usr/include/OGRE/Terrain -isystem /usr/include/OGRE/Paging -isystem /usr/include/ignition/transport8 -isystem /usr/include/ignition/msgs5 -isystem /usr/include/ignition/common3 -isystem /usr/include/ignition/fuel_tools4 -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -isystem /usr/local/include/eigen3 -isystem /usr/local/opencv3.4/include/opencv4 -isystem /usr/include/sdformat-9.10/sdf/.. -isystem /usr/include/ignition/cmake2 -isystem /usr/include/uuid -O2 -g -DNDEBUG -fPIC -Wno-deprecated-declarations -Wno-address-of-packed-member -I/usr/include/uuid -std=gnu++17 -MD -MT CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o -MF CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o.d -o CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o -c /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/src/gazebo_aruco_plugin.cpp In file included from /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/src/gazebo_aruco_plugin.cpp:31: /home/lixing/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/include/gazebo_aruco_plugin.h:42:10: fatal error: opencv2/aruco.hpp: 没有那个文件或目录 42 | #include <opencv2/aruco.hpp> | ^~~~~~~~~~~~~~~~~~~ compilation terminated. [77/115] Building CXX object CMakeFile...ir/src/gazebo_user_camera_plugin.cpp.o ninja: build stopped: subcommand failed. [1068/1072] Linking CXX executable bin/px4 FAILED: external/Stamp/sitl_gazebo-classic/sitl_gazebo-classic-build cd /home/lixing/PX4-Autopilot/build/px4_sitl_default/build_gazebo-classic && /usr/bin/cmake --build /home/lixing/PX4-Autopilot/build/px4_sitl_default/build_gazebo-classic -- -j 12 ninja: build stopped: subcommand failed. make: *** [Makefile:227:px4_sitl] 错误 1 lixing@lixing:~/PX4-Autopilot$
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值