ROS编译时提示ros::init()等ros库函数未定义就引用,然而CMakeList.txt中已经正确的应用roscpp
最近在使用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()也在各种引用的后面,函数顺序没有问题。很费解问题处在哪里?求大神帮助!