OpenCV - 2.4.10.1: 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

Hi,

I upgraded from opencv-2.4.9 to opencv-2.4.9.10.1, 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:

project(testSurf)
        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
            main.cpp
           )

        set( testSurf_LIB
            ${OpenCV_LIBS}
            )

        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:

OpenCV_LIBS=opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d

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

Comments

If I add manully "opencv_nonfree" I still can not build because I get the following error: /usr/local/lib/libopencv_nonfree.so:-1: 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