rosrun无法执行相应的可执行程序

本文介绍了解决ROS环境中创建的功能包无法通过rosrun命令找到并执行可执行文件的问题。关键在于正确配置CMakeLists.txt文件,特别是catkin_package()命令的位置。确保此命令紧跟在find_package()之后,以便正确生成并定位到可执行文件。

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

问题描述:创建好了功能区和功能包后catkin_make 编译一切正常。rosrun package_name executable_name时找不到可执行程序(按table联想不出来executable_name),编译没有报错;也进行了source devel/setup.bash,最后发现是CMakeList里边少了一句话catkin_package();这句话顺序好像也会影响到能否找到可执行程序,写的时候最好跟在find_package()这句话后面;这样就能在devel/lib/package_name目录下找到相应的可执行程序

CMakeList.txt的内容

cmake_minimum_required(VERSION 2.8.3)
project(test)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package()   ##----这句话的位置好像也会影响能否找到包,比如第一次我把这句话写在最后一行好像就有问题
include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(count count.cpp)
target_link_libraries(count ${catkin_LIBRARIES})

 

(1)有问题的catkin_make输出:

exbot@ubuntu:~/catkin_ws$ catkin_make
Base path: /home/exbot/catkin_ws
Source space: /home/exbot/catkin_ws/src
Build space: /home/exbot/catkin_ws/build
Devel space: /home/exbot/catkin_ws/devel
Install space: /home/exbot/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/exbot/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/exbot/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/exbot/catkin_ws/devel;/opt/ros/indigo
-- This workspace overlays: /home/exbot/catkin_ws/devel;/opt/ros/indigo
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/exbot/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.11
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - test
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'test'
-- ==> add_subdirectory(test)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/exbot/catkin_ws/build
####
#### Running command: "make -j1 -l1" in "/home/exbot/catkin_ws/build"
####
Linking CXX executable count
[100%] Built target count

 

(2)CMakelist里边添加catkin_package()后的输出:

exbot@ubuntu:~/catkin_ws$ catkin_make
Base path: /home/exbot/catkin_ws
Source space: /home/exbot/catkin_ws/src
Build space: /home/exbot/catkin_ws/build
Devel space: /home/exbot/catkin_ws/devel
Install space: /home/exbot/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/exbot/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/exbot/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/exbot/catkin_ws/devel;/opt/ros/indigo
-- This workspace overlays: /home/exbot/catkin_ws/devel;/opt/ros/indigo
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/exbot/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.11
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - test
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'test'
-- ==> add_subdirectory(test)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/exbot/catkin_ws/build
####
#### Running command: "make -j1 -l1" in "/home/exbot/catkin_ws/build"
####
Linking CXX executable /home/exbot/catkin_ws/devel/lib/test/count
[100%] Built target count
 

可以看出倒数第二句和之前不一样了,显示链接到了devel/lib下的可执行程序

之后source devel/setup.bash(或者为了每个终端都配置好环境变量将 source ~/catkin_ws/devel/setup.bash 这句话添加到~.bashrc中去)

然后rosrun package_name executable_name(例如我的包名和可执行程序为 rosrun test count)就可以完美运行了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值