c++ - 编译ros节点时对...的 undefined reference

标签 c++ opencv g++ ros catkin

我正在尝试编写一个使用 OpenCV 非自由组件 (SURF) 的 ROS 节点。我在使用 catkin_make 编译包时遇到了问题:

//usr/local/lib/libopencv_nonfree.so: undefined reference to `cv::ocl::integral(cv::ocl::oclMat const&, cv::ocl::oclMat&)'

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(homography_test)

## Find catkin macros and libraries
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  sensor_msgs
  cv_bridge
  image_transport
)

catkin_package(

)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
    ${catkin_INCLUDE_DIRS}
    /usr/local/include
    /usr/include
    /usr/include/gstreamer-1.0
    /usr/include/glib-2.0
    /usr/lib/x86_64-linux-gnu/glib-2.0/include
)

## Declare a cpp executable
#add_executable(display_image src/display_image_node.cpp)
add_executable(homography src/sample.cpp)

## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
#add_dependencies(homography_test homography_test_generate_messages_cpp)

## Specify libraries to link a library or executable target against
target_link_libraries(
    homography

    ${catkin_LIBRARIES}

    gstreamer-1.0
    gobject-2.0
    glib-2.0

    opencv_nonfree
    opencv_calib3d
    opencv_contrib
    opencv_core
    opencv_features2d
    opencv_flann
    opencv_gpu
    opencv_highgui
    opencv_imgproc
    opencv_legacy
    opencv_ml
    opencv_objdetect
    opencv_ocl
    opencv_photo
    opencv_stitching
    opencv_superres
    opencv_ts
    opencv_video
    opencv_videostab
    rt
    pthread
    m
    dl
)

link_directories(/usr/local/lib)

但如果我手动编译相同的代码,但不是作为 ROS 节点,一切正常。

最佳答案

opencv_ocl 库似乎没有正确链接。此外,您可以通过使用 find_package 获取您的 OpenCV 配置来大大简化您的 CMakeLists.txt 文件。尝试将这些行添加到您的 CMakeLists.txt 文件中:

find_package(OpenCV REQUIRED core ocl)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
target_link_libraries(homography ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} )

您需要指定要包含在 find_package 中的 OpenCV 库。我只列出了 coreocl,因为 ocl 似乎是您所需要的,但也可能需要其他的。

关于c++ - 编译ros节点时对...的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30493228/

相关文章:

c++ - 是否可以在 C++ 中调用没有直接引用的函数?

c++ - 如何在 g++ 中使用配置文件引导优化?

c++ - gmp 的 libgmp.so 有什么依赖?我不断收到 undefined reference

opencv - opencv中是否有用于处理Blob的好的库?

matlab - 哈里斯检测器结果在 matlab 和 opencv 中的关系

python - 如何在 Python 中正确使用 opencv.imread 的参数 `flags`?

c++ - 编译错误 Undefined symbols for architecture x86_64 :

c++ - 用于非托管 C++ 的 GDI 对象的调试器可视化工具

c++ - Win32 文件锁定读取 : how to find out who's locking them

c++ - C++ 中多个基本模板的模板特化