Ask Your Question

OpenCV SURF is there but can't be found [closed]

asked 2014-08-27 08:57:28 -0500

Metalzero2 gravatar image

I was able to run OpenCV with ROS. I have run basic things (like loading images, getting video stream ect) but I am trying to run SURF or SIFT and I get this error:

Linking CXX executable /home/jim/ROS/catkin_ws/devel/lib/opencv_ros/open
CMakeFiles/open.dir/src/open.cpp.o: In function `main':
open.cpp:(.text+0x15b): undefined reference to `cv::SURF::SURF(double, int, int, bool, bool)'
CMakeFiles/open.dir/src/open.cpp.o: In function `cv::SURF::~SURF()':
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0xe): undefined reference to `vtable for cv::SURF'
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x26): undefined reference to `vtable for cv::SURF'
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x2e): undefined reference to `vtable for cv::SURF'
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x3b): undefined reference to `VTT for cv::SURF'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/jim/ROS/catkin_ws/devel/lib/opencv_ros/open] Error 1
make[1]: *** [opencv_ros/CMakeFiles/open.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

The project name is "opencv_ros" and the code is in "open.cpp". I have include these headers:

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"

the thing is that when I run the same code in my c++ IDE (code::blocks) it runs just fine. I even found the header file and saw that it's in the correct place (according to the include I gave).

I am running ubuntu 14.04 64bit on Indigo with OpenCV 2.4.9 .

Why cant it find SURF in ROS?

edit retag flag offensive reopen merge delete

Closed for the following reason OpenCV Question: THe OpenCV community prefers to answer questions at: by tfoote
close date 2014-11-23 13:47:12.082699

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-27 15:37:31 -0500

tfoote gravatar image

Your includes are fine. You need to link against the library which provides the SURF implementation. You probably need an additional target_link_library call in your CMakeLIsts.txt to link in the appropriate library from opencv.

edit flag offensive delete link more


From what I know "opencv2/nonfree/features2d.hpp" is the file that has it. At the end of the CMakeList I have these two:

target_link_libraries(open ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

what else do I need to target for OpenCV 2.4.9 to work?

Metalzero2 gravatar image Metalzero2  ( 2014-08-27 16:41:41 -0500 )edit
tfoote gravatar image tfoote  ( 2014-08-27 17:05:03 -0500 )edit

@tfoote thanks for the links but I have done all that stuff (at least the ones I understood). I think the problem is with ROS (or how I use it) because when I run the same code from my IDE (code::blocks), everything works fine. So the OpenCV library is not the problem I think.

Metalzero2 gravatar image Metalzero2  ( 2014-08-27 17:54:24 -0500 )edit

If you don't have the symbol, you need to add something to your link line. My suggestion is that you ask opencv experts what you need to add to the linking for that to work. ROS uses they system version of openCV. If it works in codeblocks you should find out what they are linking against and make sure you are replicating that list.

tfoote gravatar image tfoote  ( 2014-08-27 18:16:16 -0500 )edit

Question Tools

1 follower


Asked: 2014-08-27 08:57:28 -0500

Seen: 5,305 times

Last updated: Aug 27 '14