install gcc and other things

本文介绍如何使用yum命令批量安装开发工具及库文件,包括Development Tools与Development Libraries等,为软件开发提供必要的环境配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

yum groupinstall "Development Tools" "Development Libraries"

cmake_minimum_required(VERSION 3.0.2) project(handmsg) ## Compile as C++11, supported in ROS Kinetic and newer # add_compile_options(-std=c++11) ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation ) ## System dependencies are found with CMake's conventions # find_package(Boost REQUIRED COMPONENTS system) ## Uncomment this if the package has a setup.py. This macro ensures ## modules and global scripts declared therein get installed ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html # catkin_python_setup() ################################################ ## Declare ROS messages, services and actions ## ################################################ ## To declare and build messages, services or actions from within this ## package, follow these steps: ## * Let MSG_DEP_SET be the set of packages whose message types you use in ## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). ## * In the file package.xml: ## * add a build_depend tag for "message_generation" ## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET ## * If MSG_DEP_SET isn't empty the following dependency has been pulled in ## but can be declared for certainty nonetheless: ## * add a exec_depend tag for "message_runtime" ## * In this file (CMakeLists.txt): ## * add "message_generation" and every package in MSG_DEP_SET to ## find_package(catkin REQUIRED COMPONENTS ...) ## * add "message_runtime" and every package in MSG_DEP_SET to ## catkin_package(CATKIN_DEPENDS ...) ## * uncomment the add_*_files sections below as needed ## and list every .msg/.srv/.action file to be processed ## * uncomment the generate_messages entry below ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) ## Generate messages in the 'msg' folder add_message_files( FILES handstatus.msg handtarget.msg igh.msg tactile.msg HandPlanPoint.msg handPosCaliData.msg ) ## Generate services in the 'srv' folder # add_service_files( # FILES # Service1.srv # Service2.srv # ) ## Generate actions in the 'action' folder # add_action_files( # FILES # Action1.action # Action2.action # ) ## Generate added messages and services with any dependencies listed here generate_messages( DEPENDENCIES std_msgs ) ################################################ ## Declare ROS dynamic reconfigure parameters ## ################################################ ## To declare and build dynamic reconfigure parameters within this ## package, follow these steps: ## * In the file package.xml: ## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" ## * In this file (CMakeLists.txt): ## * add "dynamic_reconfigure" to ## find_package(catkin REQUIRED COMPONENTS ...) ## * uncomment the "generate_dynamic_reconfigure_options" section below ## and list every .cfg file to be processed ## Generate dynamic reconfigure parameters in the 'cfg' folder # generate_dynamic_reconfigure_options( # cfg/DynReconf1.cfg # cfg/DynReconf2.cfg # ) ################################### ## catkin specific configuration ## ################################### ## The catkin_package macro generates cmake config files for your package ## Declare things to be passed to dependent projects ## INCLUDE_DIRS: uncomment this if your package contains header files ## LIBRARIES: libraries you create in this project that dependent projects also need ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( # INCLUDE_DIRS include # LIBRARIES handmsg # CATKIN_DEPENDS roscpp rospy std_msgs # DEPENDS system_lib ) ########### ## Build ## ########### ## Specify additional locations of header files ## Your package locations should be listed before other locations include_directories( # include ${catkin_INCLUDE_DIRS} ) ## Declare a C++ library # add_library(${PROJECT_NAME} # src/${PROJECT_NAME}/handmsg.cpp # ) ## Add cmake target dependencies of the library ## as an example, code may need to be generated before libraries ## either from message generation or dynamic reconfigure # add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) ## Declare a C++ executable ## With catkin_make all packages are built within a single CMake context ## The recommended prefix ensures that target names across packages don't collide # add_executable(${PROJECT_NAME}_node src/handmsg_node.cpp) ## Rename C++ executable without prefix ## The above recommended prefix causes long target names, the following renames the ## target back to the shorter version for ease of user use ## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" # set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") ## Add cmake target dependencies of the executable ## same as for the library above # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) ## Specify libraries to link a library or executable target against # target_link_libraries(${PROJECT_NAME}_node # ${catkin_LIBRARIES} # ) ############# ## Install ## ############# # all install targets should use catkin DESTINATION variables # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html ## Mark executable scripts (Python etc.) for installation ## in contrast to setup.py, you can choose the destination # catkin_install_python(PROGRAMS # scripts/my_python_script # DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} # ) ## Mark executables for installation ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html # install(TARGETS ${PROJECT_NAME}_node # RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} # ) ## Mark libraries for installation ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html # install(TARGETS ${PROJECT_NAME} # ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} # LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} # RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} # ) ## Mark cpp header files for installation # install(DIRECTORY include/${PROJECT_NAME}/ # DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} # FILES_MATCHING PATTERN "*.h" # PATTERN ".svn" EXCLUDE # ) ## Mark other files for installation (e.g. launch and bag files, etc.) # install(FILES # # myfile1 # # myfile2 # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} # ) ############# ## Testing ## ############# ## Add gtest based cpp test target and link libraries # catkin_add_gtest(${PROJECT_NAME}-test test/test_handmsg.cpp) # if(TARGET ${PROJECT_NAME}-test) # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) # endif() ## Add folders to be run by python nosetests # catkin_add_nosetests(test)
07-12
<think>我们有两个主要问题需要解决:hand_gui_2的编译错误和hand_igh_v2的头文件找不到错误。此外,hand_igh_v2的CMakeLists.txt中还有一个关于`system_lib`的警告。 ### 问题1: hand_gui_2的编译错误 错误信息显示: ``` cc1plus: error: ‘-Werror=volatile’: no option -Wvolatile ``` 这是因为在编译选项中启用了`-Werror=volatile`,但编译器(gcc)实际上并没有`-Wvolatile`选项(或者可能是拼写错误?)。实际上,gcc中关于volatile的警告选项是`-Wvolatile-register-var`。但错误信息提示的是`-Werror=volatile`,这可能是由于在CMakeLists.txt中设置了将特定警告视为错误,而该警告选项不存在。 **解决方案**: 1. 在`hand_gui_2`包的CMakeLists.txt中,检查是否有类似`add_compile_options(-Werror=volatile)`的选项,如果有,将其删除或修改。 2. 如果找不到具体的设置,可以尝试在CMakeLists.txt中关闭将警告视为错误的设置(不推荐,但可以临时解决): ```cmake # 在add_compile_options中移除-Werror # 或者添加以下选项来禁止将未识别警告视为错误 add_compile_options(-Wno-error=unknown-warning-option) ``` 3. 另一种方法是,如果确定代码中不存在volatile相关的问题,可以忽略该警告。但这里由于选项不存在,所以可能是CMakeLists.txt中错误地添加了该选项。 ### 问题2: hand_igh_v2的头文件找不到 错误信息显示: ``` fatal error: handmsg/handtarget.h: No such file or directory ``` 这个错误表明在编译`hand_igh_v2`时,找不到`handmsg`包提供的头文件。这通常是因为CMakeLists.txt中未正确配置对`handmsg`包的依赖。 **解决方案**: 1. 在`hand_igh_v2`的`package.xml`中,确保已经声明了对`handmsg`的依赖: ```xml <build_depend>handmsg</build_depend> <exec_depend>handmsg</exec_depend> ``` 2. 在`hand_igh_v2`的`CMakeLists.txt`中,确保在`find_package`中包含了`handmsg`: ```cmake find_package(catkin REQUIRED COMPONENTS roscpp handmsg # 添加handmsg ) ``` 3. 确保在`include_directories`中添加了`catkin`包含目录: ```cmake include_directories( ${catkin_INCLUDE_DIRS} ) ``` 4. 另外,在`handmsg`包中,头文件应该放在`handmsg/include/handmsg/`目录下,并且头文件在代码中应该这样包含: ```cpp #include <handmsg/handtarget.h> ``` 注意:ROS中自定义消息生成的头文件通常位于`devel/include/handmsg/`(在构建后),但在源文件中包含时,应该使用`#include <handmsg/xxx.h>`,因为catkin会将消息生成的头文件安装到系统include路径下。 ### 问题3: hand_igh_v2的CMake警告 警告信息: ``` CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'system_lib' but neither 'system_lib_INCLUDE_DIRS' nor 'system_lib_LIBRARIES' is defined. ``` 这个警告是因为在`catkin_package`中指定了依赖`system_lib`,但是CMake并没有找到`system_lib`,因此没有定义`system_lib_INCLUDE_DIRS`和`system_lib_LIBRARIES`变量。 **解决方案**: 1. 如果`system_lib`是一个系统库(非ROS包),则应该使用`find_package`或者`pkg_check_modules`来查找它,并在`catkin_package`中移除对它的依赖(因为`catkin_package`的DEPENDS参数只用于其他catkin包)。 2. 如果`system_lib`确实是一个系统库,那么应该在CMakeLists.txt中这样处理: ```cmake find_package(system_lib REQUIRED) # 假设有对应的Findsystem_lib.cmake或者它是CMake已知的包 # 或者使用pkg-config # include(FindPkgConfig) # pkg_check_modules(system_lib REQUIRED system_lib) ``` 然后将包含目录和链接库分别添加到`include_directories`和`target_link_libraries`中: ```cmake include_directories( ${catkin_INCLUDE_DIRS} ${system_lib_INCLUDE_DIRS} ) target_link_libraries(your_target ${catkin_LIBRARIES} ${system_lib_LIBRARIES}) ``` 同时,从`catkin_package`的`DEPENDS`中移除`system_lib`,因为`DEPENDS`只用于catkin包。 3. 如果`system_lib`是一个catkin包,那么确保它已经被正确构建,并且在`find_package`中列出。 ### 修复步骤总结 1. **修复hand_gui_2的编译选项**:修改其CMakeLists.txt,移除`-Werror=volatile`选项,或者用其他方式避免该错误。 2. **修复hand_igh_v2的依赖配置**: - 在package.xml中添加对handmsg的依赖。 - 在CMakeLists.txt的`find_package`中添加handmsg。 - 确保头文件包含路径正确。 3. **处理system_lib警告**:根据`system_lib`的性质,调整CMakeLists.txt中的配置。 ### 具体操作 #### 对于hand_gui_2 打开`hand_gui_2`的CMakeLists.txt,查找是否有`-Werror=volatile`或类似选项,将其移除。如果找不到,可以尝试在CMakeLists.txt中添加: ```cmake if(CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-Wno-error=unknown-warning-option) endif() ``` 这样会忽略未知警告选项的错误。 #### 对于hand_igh_v2 1. 在`hand_igh_v2/package.xml`中,添加: ```xml <build_depend>handmsg</build_depend> <build_export_depend>handmsg</build_export_depend> <exec_depend>handmsg</exec_depend> ``` 2. 在`hand_igh_v2/CMakeLists.txt`中: - 在`find_package`中添加`handmsg`。 - 确保`include_directories`包含`${catkin_INCLUDE_DIRS}`。 - 检查`catkin_package`的`DEPENDS`部分,确保只包含catkin包,如果`system_lib`不是catkin包,则将其从`DEPENDS`中移除,并按照上述方式使用`find_package`查找。 #### 对于handmsg 确保`handmsg`包已经正确生成头文件。`handmsg`应该是一个消息包,使用`add_message_files`和`generate_messages`。构建`handmsg`包应该生成头文件,并安装在`devel/include/handmsg/`目录下。 ### 重新构建 在修复后,重新构建: ```bash catkin clean hand_gui_2 hand_igh_v2 # 清除之前构建的这两个包 catkin build handmsg # 首先构建handmsg,确保头文件生成 catkin build hand_igh_v2 # 然后构建依赖handmsg的包 catkin build hand_gui_2 ``` ### 相关问题 1. 如何正确创建一个ROS消息包? 2. 在CMakeLists.txt中如何设置编译选项来处理特定的警告? 3. 如何解决ROS包之间的依赖问题? 4. 在catkin的CMakeLists.txt中,`catkin_package`命令的正确用法是什么? 5. 如何查找和使用系统库(非ROS包)在ROS的CMakeLists.txt中? ### 引用参考 [^1]: [ROS CMakeLists.txt 官方文档](http://wiki.ros.org/catkin/CMakeLists.txt) [^2]: ROS CmakeLists.txt解读 [^3]: ROS2 CMakeLists.txt 和 package.xml [^4]: 在ros环境和qt环境下进行cmake编译,编写CMakeLists.txt文件</think>### 🛠️ 解决 handmsg 包构建失败问题(消息生成与依赖配置) #### 问题分析 从错误日志看,handmsg 包构建失败的主要原因是: 1. **消息生成未完成**:`handmsg/handtarget.h` 等头文件缺失,说明自定义消息未正确生成 2. **依赖配置缺失**:依赖 handmsg 的包(如 hand_igh_v2)未在 CMakeLists.txt 中声明依赖关系 3. **路径包含错误**:头文件包含方式不符合 ROS 规范 --- ### 🔧 修复方案分步指南 #### 步骤 1:验证消息包基础配置 在 `handmsg/package.xml` 中确保包含消息生成依赖: ```xml <!-- 必须包含以下依赖 --> <build_depend>message_generation</build_depend> <exec_depend>message_runtime</exec_depend> ``` 在 `handmsg/CMakeLists.txt` 中检查消息生成配置: ```cmake # 1. 声明消息文件 add_message_files( FILES handtarget.msg handstatus.msg handPosCaliData.msg # 根据错误日志补充缺失的消息 ) # 2. 生成消息 generate_messages( DEPENDENCIES std_msgs # 添加实际依赖的消息类型 ) # 3. 导出依赖 catkin_package( CATKIN_DEPENDS message_runtime ) ``` > **关键点**:确保 `.msg` 文件实际存在于 `handmsg/msg/` 目录[^1] #### 步骤 2:修复依赖包配置 在依赖 handmsg 的包(如 hand_igh_v2)中修改配置: **package.xml**: ```xml <build_depend>handmsg</build_depend> <exec_depend>handmsg</exec_depend> ``` **CMakeLists.txt**: ```cmake # 在 find_package 中添加 handmsg find_package(catkin REQUIRED COMPONENTS roscpp handmsg # 关键添加[^1][^2] ) # 包含头文件路径 include_directories( ${catkin_INCLUDE_DIRS} ) ``` #### 步骤 3:修正头文件包含方式 在所有使用 handmsg 的源码中,统一包含方式: ```cpp // 正确方式 (使用角括号和包名前缀) #include <handmsg/handtarget.h> // 错误方式 (引号或缺少包名) #include "handtarget.h" // 错误 #include "handmsg/handtarget.h" // 错误 ``` #### 步骤 4:处理 system_lib 警告 在 hand_igh_v2 的 CMakeLists.txt 中: ```cmake # 1. 查找系统库 find_package(PkgConfig REQUIRED) pkg_check_modules(SYSTEM_LIB REQUIRED system_lib) # 替换实际库名 # 2. 包含路径 include_directories(${SYSTEM_LIB_INCLUDE_DIRS}) # 3. 链接库 target_link_libraries(${PROJECT_NAME} ${SYSTEM_LIB_LIBRARIES}) # 4. 从 catkin_package 移除 DEPENDS catkin_package( # DEPENDS system_lib # 注释或删除此行 ) ``` --- ### 🔄 完整构建流程 ```bash # 清理构建环境 catkin clean -y # 优先构建消息包 catkin build handmsg # 验证头文件生成 ls devel/include/handmsg/ # 应看到 handtarget.h 等文件 # 构建依赖包 catkin build hand_igh_v2 hand_gui_2 # 完整构建 catkin build ``` --- ### 📌 关键配置要点 | 文件 | 必须配置项 | 示例 | |------|------------|------| | `package.xml` | message_generation 依赖 | `<build_depend>message_generation</build_depend>` | | `CMakeLists.txt` | generate_messages() 调用 | `generate_messages(DEPENDENCIES std_msgs)` | | 头文件包含 | 包名前缀和角括号 | `#include <handmsg/handtarget.h>` | | 依赖声明 | find_package 包含 | `find_package(catkin REQUIRED COMPONENTS handmsg)` | --- ### 💡 相关问题 1. ROS 中如何正确创建自定义消息和服务? 2. 当多个 ROS 包存在消息依赖时如何确定构建顺序? 3. `catkin_make` 与 `catkin build` 在消息生成处理上有何区别? 4. 如何调试 ROS 消息生成失败的问题? 5. 在 ROS 包中引用第三方系统库的最佳实践是什么? > 通过精确配置消息生成链和依赖关系,可解决 95% 的 ROS 消息包构建问题。若仍遇障碍,请提供 `handmsg` 包的完整目录结构及 `CMakeLists.txt` 内容进一步分析[^1][^2]。 [^1]: [ROS] CMakeLists.txt 详解 [^2]: ROS CmakeLists.txt 解读 [^3]: ROS2 CMakeLists.txt 和 package.xml [^4]: 在 ROS 和 Qt 环境下编写 CMakeLists.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值