最近在使用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()也在各種參考的后面,函式順序沒有問題。很費解問題處在哪里?求大神幫助!
uj5u.com熱心網友回復:
我在編譯ROS helloworld也碰到同樣的問題,只要參考ROS函式就提示“未定義的參考”,當注釋到main函式內的ROS函式再編譯,就沒有錯誤了。CMakeLists.txt,package.xml,source 環境變數,都檢查n遍了。同求大神幫忙!uj5u.com熱心網友回復:
找到解決問題的辦法了,重新建作業空間和程式包,完美解決問題!轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/165434.html
標籤:智能硬件
上一篇:找出唯一成對的數(異或運算)
下一篇:編譯出錯不知道哪里有問題
