-2

I have an opencv project and all worked well so far until I just tried to rebuild my code today: I got the following error:

undefined reference to `cv::KalmanFilter::KalmanFilter(int, int, int, int)'

undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'

undefined reference to `cv::waitKey(int)'

I am not sure why this error occurs, I could only assume that it might be somehow connected with the fact that I ran sudo apt-get autoremove or sudo apt-get upgrade. The only other thing I did before was installing arduino.

I am not sure why I get this error as I was always able to compile until today.

Can it be that the opencv include for the kalman filter has changed? Here is a snipped of my includes:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/video/video.hpp> //for kalman filter
//Include headers for OpenCV GUI handling
#include <opencv2/highgui/highgui.hpp>

In my CMakeLists.txt:

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
)

include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${OpenCV_LIB_COMPONENTS}
    ${OpenCV_LIBRARIES}

I have opencv 3.3.1 running.

user0042
  • 7,917
  • 3
  • 24
  • 39
sqp_125
  • 538
  • 6
  • 21
  • 4
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Algirdas Preidžius Dec 16 '17 at 09:42

1 Answers1

0

Just found the solution:

I had to link against opencv_libs.

In my CMakeLists.txt I added:

target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(example_node ${PROJECT_NAME})

I am not sure why my code worked before but stopped working now. Anyway now it compiles again :)

sqp_125
  • 538
  • 6
  • 21