小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
No executable found(ros2 run的时候找不到头文件)
-
ubuntu20.04
在B站视频《面向过程思想编写cpp节点》https://www.bilibili.com/video/BV1gr4y1Q7j5/?p=25&spm_id_from=pageDriver&vd_source=5340b8baff6fb33e9d5215026c441964
中。最后会出现此问题
ros2@ros2-virtual-machine:~/town_ws$ ros2 run village_wang wang2_node No executable found
查阅资料说 使用ros2 run的时候找不到头文件,是因为现在和ros1不一样了。你必须要将可执行文件注册,ros2命令才找得到。但是此前已经在CMakeLists头文件中进行注册了
下面文档CMakeLists.txt中有关的部分代码
ament_package() add_executable(wang2_node src/wang2.cpp) ament_target_dependencies(wang2_node rclcpp) install(TARGETS wang2_node DESTINATION lib/${PROJECT_NAME} ) ament_package()
下面是wang.cpp代码
#include "rclcpp/rclcpp.hpp" int main(int argc,char ** argv) { rclcpp::init(argc,argv); auto node = std::make_shared<rclcpp::Node>("wang2"); RCLCPP_INFO(node->get_logger(),"大家好,我是单身狗wang2."); rclcpp::spin(node); rclcpp::shutdown(); }
下面是运行中的结果
ros2@ros2-virtual-machine:~/town_ws$ colcon build --packages-select village_wang Starting >>> village_wang Finished <<< village_wang [0.19s] Summary: 1 package finished [0.40s] ros2@ros2-virtual-machine:~/town_ws$ source install/setup.bash ros2@ros2-virtual-machine:~/town_ws$ ros2 pkg list | grep vill village_li village_wang ros2@ros2-virtual-machine:~/town_ws$ ros2 run village_wang wang2_node No executable found
-
@march_xiong 试试这个指令,看看会显示什么
cd src/village_wang mkdir build cd build cmake .. make
-
@小鱼
运行上述后的结果ros2@ros2-virtual-machine:~/town_ws$ cd src/village_wang ros2@ros2-virtual-machine:~/town_ws/src/village_wang$ mkdir build mkdir: 无法创建目录 "build": 文件已存在 ros2@ros2-virtual-machine:~/town_ws/src/village_wang$ cd build ros2@ros2-virtual-machine:~/town_ws/src/village_wang/build$ cmake .. -- Found ament_cmake: 1.3.3 (/opt/ros/humble/share/ament_cmake/cmake) -- Found rclcpp: 16.0.3 (/opt/ros/humble/share/rclcpp/cmake) -- Found rosidl_generator_c: 3.1.4 (/opt/ros/humble/share/rosidl_generator_c/cmake) -- Found rosidl_adapter: 3.1.4 (/opt/ros/humble/share/rosidl_adapter/cmake) -- Found rosidl_generator_cpp: 3.1.4 (/opt/ros/humble/share/rosidl_generator_cpp/cmake) -- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c -- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp -- Found rmw_implementation_cmake: 6.1.1 (/opt/ros/humble/share/rmw_implementation_cmake/cmake) -- Found rmw_fastrtps_cpp: 6.2.2 (/opt/ros/humble/share/rmw_fastrtps_cpp/cmake) -- Using RMW implementation 'rmw_fastrtps_cpp' as default -- Found ament_lint_auto: 0.12.5 (/opt/ros/humble/share/ament_lint_auto/cmake) -- Added test 'cppcheck' to perform static code analysis on C / C++ code -- Configured cppcheck include dirs: -- Configured cppcheck exclude dirs and/or files: -- Added test 'lint_cmake' to check CMake code style -- Added test 'uncrustify' to check C / C++ code style -- Configured uncrustify additional arguments: -- Added test 'xmllint' to check XML markup files -- Configuring done -- Generating done -- Build files have been written to: /home/ros2/town_ws/src/village_wang/build ros2@ros2-virtual-machine:~/town_ws/src/village_wang/build$ make ros2@ros2-virtual-machine:~/town_ws/src/village_wang/build$
然后我在新的终端重新执行ros2 run程序,结果
ros2@ros2-virtual-machine:~/town_ws$ colcon build --packages-select village_wang Starting >>> village_wang Finished <<< village_wang [0.17s] Summary: 1 package finished [0.35s] ros2@ros2-virtual-machine:~/town_ws$ source install/setup.bash ros2@ros2-virtual-machine:~/town_ws$ ros2 pkg list | grep vill village_li village_wang ros2@ros2-virtual-machine:~/town_ws$ ros2 run village_wang wang2_node No executable found ros2@ros2-virtual-machine:~/town_ws$
发现报相同错误
No executable found
后续发现找不到wang2这个节点
ros2@ros2-virtual-machine:~/town_ws$ ros2 node list /li4 ros2@ros2-virtual-machine:~/town_ws$ ros2 node info /wang2 Unable to find node '/wang2' ros2@ros2-virtual-machine:~/town_ws$
-
@march_xiong 1.尝试检查一下CMakeLists.txt是否写入
2.工作空间是否创建错误,
文件目录为.
└── src
└── example_topic_rclcpp
├── CMakeLists.txt
├── include
│ └── example_topic_rclcpp
├── package.xml
└── src
└── topic_publisher_01.cpp5 directories, 3 files
-
@march_xiong 具体参考https://fishros.com/d2lros2foxy/#/chapt3/3.6.1%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AAC++%E5%8A%9F%E8%83%BD%E5%8C%85
-
@醉后不知天在水
目录如下
就是多了个构造build后的文件夹
重新编译后报错情况如下
ros2@ros2-virtual-machine:~/town_ws$ colcon build --packages-select village_wang Starting >>> village_wang --- stderr: village_wang CMake Error at /opt/ros/humble/share/ament_cmake_core/cmake/environment_hooks/ament_environment_hooks.cmake:29 (message): ament_environment_hooks() must be called before ament_generate_package_environment() (which is invoked by ament_package()) Call Stack (most recent call first): /opt/ros/humble/share/ament_cmake_core/cmake/environment_hooks/ament_cmake_environment_hooks_package_hook.cmake:20 (ament_environment_hooks) /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include) /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_package.cmake:66 (ament_execute_extensions) CMakeLists.txt:33 (ament_package) gmake: *** [Makefile:226:cmake_check_build_system] 错误 1 --- Failed <<< village_wang [1.41s, exited with code 2] Summary: 0 packages finished [1.76s] 1 package failed: village_wang 1 package had stderr output: village_wang
主要是这块
CMake Error at /opt/ros/humble/share/ament_cmake_core/cmake/environment_hooks/ament_environment_hooks.cmake:29 (message): ament_environment_hooks() must be called before ament_generate_package_environment() (which is invoked by ament_package())
就是这个环境的声明问题,不过CMakelist中的这行代码是照着视频敲的
CMakelist进行了读写cmake_minimum_required(VERSION 3.8) project(village_wang) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() ament_package() add_executable(wang2_node src/wang2.cpp) ament_target_dependencies(wang2_node rclcpp) install(TARGETS wang2_node DESTINATION lib/${PROJECT_NAME} )
最下面的三段是视频的教程
这个ament_package()
网上查找结果
因为ament package是构建系统独立的,所以有各种各样的ament包,比如ament CMake package、ament Python package等。
所以这个报错,不知道应该如何解决
-
@march_xiong 将
ament_package()
移到最后一行cmake_minimum_required(VERSION 3.8) project(example_cpp) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() add_executable(node_01 src/node_01.cpp) ament_target_dependencies(node_01 rclcpp) add_executable(node_03 src/node_03.cpp) ament_target_dependencies(node_03 rclcpp) install(TARGETS node_01 DESTINATION lib/${PROJECT_NAME} ) install(TARGETS node_03 DESTINATION lib/${PROJECT_NAME} ) ament_package()
-
@小鱼
更改后确实运行正常了 小鱼好厉害
不过有点好奇这个库要最后声明么? -
@小鱼 cmake_minimum_required(VERSION 3.8)
project(cpp01_launch)if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)the following line skips the linter which checks for copyrights
comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
the following line skips cpplint (only works in a git repo)
comment the line when this package is in a git repo and when
a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
ament_package()我的ament_package()就是在最后一行 为什么运行后的结果还是No executable found
-
@小鱼 ament_package()在最后一行还是不行
-
@2041525450 我保证,视频和书里绝对没有你敲的这句命令