ROS中编译通过但是遇到可执行文件找不到的问题

        编写一个ros package,catkin_make编译后却无法Tab补全包内的节点名称双击Tab甚至没有任何可执行节点信息,手动写全也出现如下错误:

[rosrun] Couldn't find executable named XXXXXXXXXXXX

        问题出在add_executable()以及target_link_libraries()出现的位置。

        值得注意的是第一段代码的位置一定要在第二段之前,否则在devel/lib里面是无法生成编译后的文件的。

# Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)
add_executable(basic_shapes src/basic_shapes.cpp)
target_link_libraries(basic_shapes ${catkin_LIBRARIES})

add_executable(points_and_lines src/points_and_lines.cpp)
target_link_libraries(points_and_lines ${catkin_LIBRARIES})

 最后位置正确的效果如下述代码。


###################################
## 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 using_markers
#  CATKIN_DEPENDS roscpp visualization_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}/using_markers.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/using_markers_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}
# )
add_executable(basic_shapes src/basic_shapes.cpp)
target_link_libraries(basic_shapes ${catkin_LIBRARIES})

add_executable(points_and_lines src/points_and_lines.cpp)
target_link_libraries(points_and_lines ${catkin_LIBRARIES})

再次catkin_make就可以看到结果了。

 

 

  • 10
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
回答: 如果在PyCharm无法接收到ROS话题,可能是由于以下几个原因导致的: 1. 请确保你已经正确初始化了ROS节点,并且节点名称与订阅者代码的节点名称一致。在你的代码,节点名称是"pose_subscriber"。\[2\] 2. 确保你的订阅者代码正确指定了需要订阅的话题。在你的代码,你需要订阅的话题是"/turtle1/pose"。\[2\] 3. 确保你的订阅者代码使用了正确的回调函数来处理接收到的消息。在你的代码,回调函数是poseCallback。\[2\] 4. 检查你的代码是否正确编译和构建。你需要在CMakeLists.txt文件添加订阅者的可执行文件,并链接所需的库。\[3\] 如果你仍然无法接收到话题,请检查你的ROS环境是否正确设置,并确保你的网络连接正常。另外,你可以尝试使用rostopic命令行工具来检查话题是否发布了消息,以及使用roswtf命令来检查ROS系统的配置是否正确。 希望这些信息对你有帮助! #### 引用[.reference_title] - *1* *2* [【ROS入门21讲】订阅者Subscriber的编程使用](https://blog.csdn.net/g944468183/article/details/123841624)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [pycharm开发Prometheus](https://blog.csdn.net/Q_L_Y/article/details/129968267)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值