参考链接:https://github.com/dji-sdk/Guidance-SDK-ROS
将Guidance-SDK-ROS 包拷贝进我的工作空间后使用catkin_make
进行编译,出错如下:
CMakeFiles/guidanceNodeCalibration.dir/src/GuidanceNodeCalibration.cpp.o: In function `my_callback(int, int, char*)':
GuidanceNodeCalibration.cpp:(.text+0x9a4): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
GuidanceNodeCalibration.cpp:(.text+0xb9b): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
GuidanceNodeCalibration.cpp:(.text+0xddc): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status
Guidance-SDK-ROS/CMakeFiles/guidanceNodeCalibration.dir/build.make:145: recipe for target '/home/cyril/Disk/ros_robotics_projects_ws/devel/lib/guidance/guidanceNodeCalibration' failed
make[2]: *** [/home/Disk/ros_robotics_projects_ws/devel/lib/guidance/guidanceNodeCalibration] Error 1
CMakeFiles/Makefile2:447: recipe for target 'Guidance-SDK-ROS/CMakeFiles/guidanceNodeCalibration.dir/all' failed
make[1]: *** [Guidance-SDK-ROS/CMakeFiles/guidanceNodeCalibration.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j2 -l2" failed
在Google上搜索过后基本没有找到明确的解决办法,但是能够确定的方向就是编译时没有正确链接到OpenCV的库。所以基本上要从OpenCV以及CMakelist
的设置上来寻找答案了。
通过编译打印的日志:
-- +++ processing catkin package: 'guidance'
-- ==> add_subdirectory(Guidance-SDK-ROS)
System is: x86_64
-- 64bit detected
-- OpenCV library status:
-- version: 2.4.9.1
-- libraries: opencv_core;opencv_highgui
-- include path: /opt/ros/kinetic/include/opencv;/opt/ros/kinetic/include
可以看到我这里链接的OpenCV版本是2.4.9.1
,然而通过查看OpenCV的版本:
pkg-config --modversion opencv
3.4.2
我的OpenCV是3.4.2
,所以这里出问题的地方应该是链接OpenCV时冲突了,导致找不到对应的包了。
我们查看Guidance-SDK-ROS的CMakeList.txt文件:
cmake_minimum_required(VERSION 2.8.3)
project(guidance)
find_package(catkin REQUIRED COMPONENTS
roscpp
cv_bridge
std_msgs
sensor_msgs
geometry_msgs
)
find_package(OpenCV 2 REQUIRED core highgui)
catkin_package(
)
include_directories(
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
include
)
message("System is: " ${CMAKE_SYSTEM_PROCESSOR})
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
message("-- 32bit detected")
link_directories(lib/x86)
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
message("-- 64bit detected")
link_directories(lib/x64)
endif ()
else()
message("-- Non-linux platform detected but sorry we do not support :D")
endif ()
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" )
message("-- " ${CMAKE_SYSTEM_PROCESSOR} " detected")
link_directories(lib/XU3)
else ()
endif ()
##cyril add the following
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
link_libraries(
${OpenCV_LIBS}
${catkin_LIBRARIES}
DJI_guidance
usb-1.0
yaml-cpp)
add_executable(guidanceNode
src/GuidanceNode.cpp
src/DJI_utility.cpp)
add_executable(guidanceNodeTest
src/GuidanceNodeTest.cpp)
add_executable(guidanceNodeCalibration
src/GuidanceNodeCalibration.cpp
src/DJI_utility.cpp)
参考了这篇帖子: https://blog.csdn.net/u012816621/article/details/51732932
我在find_package
这句话前面去设置opencv的OpenCV文件夹位置,我的ROS
中也装有OpenCV的包,那么就将ROS中的这个文件夹路径加进去/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv
修改如下:
###下面的set就是自己添加的,然后将原来find_package中的OpenCV 2 改成OpenCV
set(OpenCV_DIR /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv)
find_package(OpenCV REQUIRED core highgui)
catkin_package(
)
include_directories(
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
include
)
重新在工作空间进行编译,就成功通过了!