ROS编译时提示ros::init()等ros库函数未定义就引用,然而CMakeList.txt中已经正确的应用roscpp

Vince541 2017-09-21 04:48:07
最近在使用ROBOTIS对Thormang3的模拟器。原本可以编译成功的项目,突然在某一次编译报错:
CMakeFiles/hello_world.dir/src/hello_world.cpp.o:在函数‘main’中:

hello_world.cpp:(.text+0x61):对‘ros::init(int&, char**, std::string const&, unsigned int)’未定义的引用

hello_world.cpp:(.text+0xbd):对‘ros::NodeHandle::NodeHandle(std::string const&, std::map, std::allocator > > const&)’未定义的引用
.
…………

…………

CMakeFiles/hello_world.dir/src/hello_world.cpp.o:在函数‘main’中:

hello_world.cpp:(.text+0x61):对‘ros::init(int&, char**, std::string const&, unsigned int)’未定义的引用

hello_world.cpp:(.text+0xbd):对‘ros::NodeHandle::NodeHandle(std::string const&, std::map, std::allocator > > const&)’未定义的引用


推测是CMakeList.txt没有正确引用roscpp,查看该cpp对应的CMakeList.txt如下:


################################################################################
# CMake
################################################################################
cmake_minimum_required(VERSION 2.8.3)
project(thormang3_gazebo)

################################################################################
# Packages
################################################################################
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
)

################################################################################
# Declare ROS messages, services and actions
################################################################################

################################################################################
# Declare ROS dynamic reconfigure parameters
################################################################################

################################################################################
# Catkin specific configuration
################################################################################
catkin_package(
CATKIN_DEPENDS
roscpp
std_msgs
)

################################################################################
# Build
################################################################################
include_directories(
${catkin_INCLUDE_DIRS}
)

add_executable(gazebo_grip_pub
src/gazebo_grip_pub.cpp
)

target_link_libraries(gazebo_grip_pub
${catkin_LIBRARIES}
)

################################################################################
# Install
################################################################################
install(TARGETS gazebo_grip_pub
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY config
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

install(DIRECTORY worlds
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

################################################################################
# Test
################################################################################


从上面看到应该已经正确引用roscpp, 而且add_executable()也在各种引用的后面,函数顺序没有问题。很费解问题处在哪里?求大神帮助!
...全文
3516 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_41391337 2020-10-09
  • 打赏
  • 举报
回复
我在编译ROS helloworld也碰到同样的问题,只要引用ROS函数就提示“未定义的引用”,当注释到main函数内的ROS函数再编译,就没有错误了。CMakeLists.txt,package.xml,source 环境变量,都检查n遍了。同求大神帮忙!
weixin_41391337 2020-10-09
  • 打赏
  • 举报
回复 3
找到解决问题的办法了,重新建工作空间和程序包,完美解决问题!

1,616

社区成员

发帖
与我相关
我的任务
社区描述
智能硬件,智能手表,可穿戴设备,智能电视,谷歌眼镜,Google Glass 相关讨论。
社区管理员
  • 智能硬件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧