OpenCV - error: undefined reference to `vtable for cv::SURF'

asked 2015-02-26 09:01:43 -0500

wagp11 gravatar image

updated 2015-02-26 15:55:38 -0500


I upgraded from opencv-2.4.9 to opencv-, because I was missing the CUDA support, that I didn't setup in my previous installation. I test some programs I wrote with my previous installation and everything seemed to be fine until I tried the features2D tutorial code from: Features2D + Homography to find a known object

I get the errors:

 error: undefined reference to `cv::SURF::SURF(double, int, int, bool, bool)'
 error: undefined reference to `cv::SURF::SURF()'
 error: undefined reference to `vtable for cv::SURF'

The includes are those of the example code. I use cmake to build all together and my CMakeLists.txt Looks like follows:

        cmake_minimum_required(VERSION 2.8)

        set( CMAKE_BUILD_TYPE Debug )

        set( CMAKE_CXX_FLAGS "-Wall" )
       # OpenCV Handling
        find_package( OpenCV REQUIRED )

        include_directories( ${CMAKE_CURRENT_BINARY_DIR} )

        # General
        set( testSurf_SRC

        set( testSurf_LIB

        add_executable( ${PROJECT_NAME} ${testSurf_SRC} )
        target_link_libraries( ${PROJECT_NAME} ${testSurf_LIB} )

It is a problem with the linker, but I can't see where the problem is, given that I setup the libraries im my Cmake file correctly. In fact the same CMakeLists worked before the upgrade. Thank you for helping community.

Follow up: I used message("OpenCV_LIBS=${OpenCV_LIBS}")to print out the result of find_package(OpenCV REQUIRED) and the result was:


No opencv_nonfree shows up. I am trying to figure out why opencv_nonfree does not show up. I printed the value of ${OpenCV_LIBS} from a project I build before the reinstallation and there ${OpenCV_LIBS} contains the opencv_nonfree part.

edit retag flag offensive close merge delete


If I add manully "opencv_nonfree" I still can not build because I get the following error: /usr/local/lib/ error: undefined reference tocv::ocl::integral(cv::ocl::oclMat const&, cv::ocl::oclMat&)'`

wagp11 gravatar imagewagp11 ( 2015-02-26 11:09:40 -0500 )edit

I have the opencv_nonfree module shown in the message, but I still have the eror: error: undefined reference to 'cv::ocl::integral(cv::ocl::oclMat const&, cv::ocl::oclMat&)'

张京林 gravatar image张京林 ( 2016-08-22 04:37:14 -0500 )edit

I solved this problem by change the order of target_link_libraries, like this: TARGET_LINK_LIBRARIES( test ${OpenCV_LIBS} ${catkin_LIBRARIES} OpenCV first, then catkin

张京林 gravatar image张京林 ( 2016-08-22 04:52:32 -0500 )edit