典型链接器错误:c ++中对CV方法的未定义引用

时间:2015-08-31 13:19:35

标签: linker cmake undefined-reference

我正在尝试编译和构建一个使用ROS和OpenCV库的项目。我在src文件夹中有.cpp文件,在include文件夹中有.h文件。

这是我的CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8.3)
project(uwsim_imgproc)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  roscpp
  sensor_msgs
  std_msgs
  image_transport
)

find_package(OpenCV REQUIRED)

catkin_package(
INCLUDE_DIRS include
LIBRARIES uwsim_imgproc filters
CATKIN_DEPENDS cv_bridge roscpp sensor_msgs std_msgs
#  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS} 
  include
)

link_directories( 
  ${OpenCV_LINK_DIRS}
)

add_library(filters
        src/Obstacle.cpp
        src/HorizonDetector.cpp
        src/GenericTools.cpp
        src/Kalman.cpp
        src/HungarianAlg.cpp
        src/Ctracker.cpp
)

add_executable(cameraSubscriber src/main.cpp)

add_dependencies(cameraSubscriber ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(cameraSubscriber
   ${catkin_LIBRARIES}
   ${OpenCV_LIBRARIES}
   filters
 )

当我启动内部运行make的catkin_make时,我收到此错误:

lib/libfilters.so: undefined reference to `cv::KalmanFilter::predict(cv::Mat const&)'
lib/libfilters.so: undefined reference to `cv::KalmanFilter::correct(cv::Mat const&)'
lib/libfilters.so: undefined reference to `cv::KalmanFilter::KalmanFilter(int, int, int, int)'
lib/libfilters.so: undefined reference to `cv::groupRectangles(std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, int, double)'

我看一下类似的问题,但所提供的解决方案并不适合我。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

正如您的错误输出所示,filters库使用OpenCV库中的符号,但未与其链接。你的CMakeLists.txt应该这样做:

target_link_libraries(filters ${OpenCV_LIBRARIES})