Ask Your Question

Undefined reference to algorithm

asked 2013-01-07 20:08:51 -0500

Szczepan gravatar image

updated 2013-01-08 07:40:42 -0500

I want to write a program for a raspberry pi witch can recognize road signs. I found that tutorial but when I try to run that I got following error "undefined reference to cv::Algorithm::~Algorithm". I'm including same library including features2d.hpp witch is now moved to the nonfree:

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2013-01-08 10:21:50 -0500

Guanta gravatar image

updated 2013-01-09 04:44:49 -0500

First, I'd include

#include <opencv2/nonfree/nonfree.hpp>

Second you need to initialize the non-free module:


edit Maybe the following CMakeLists.txt helps you building it (afaik the pkg-config file is still broken in the current opencv-version):

cmake_minimum_required(VERSION 2.8)
find_package( OpenCV REQUIRED )
if( OpenCV_FOUND )
list( APPEND ThirdParty_LIBS ${OpenCV_LIBS} )
    include_directories( ${OpenCV_INCLUDE_DIRS} )
endif( OpenCV_FOUND )

set(${PROJECT_NAME}_SRC test.cpp)
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SRC})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
edit flag offensive delete link more


I got next error. I checked but there is no syntax error. initModule_nonfree was not declared in the scope. Edit: Now I added nonfree.hpp and i got error "undefined reference to 'cv::initModule_nonfree()"

Szczepan gravatar imageSzczepan ( 2013-01-08 15:32:25 -0500 )edit

Then, in your building process is something wrong! I just checked the example and modified it according to my post above and it built without an error. Maybe my CMakeLists.txt file which I used to build the test.cpp helps you to build it, just use ccmake for configuring it and then make to build it.

Guanta gravatar imageGuanta ( 2013-01-09 04:42:12 -0500 )edit

This is an old post, I know, but the Cmake trick did it for me, after I had installed nonfree from a repository on Ubuntu 14.04. Thanks!

alrekr gravatar imagealrekr ( 2015-12-15 13:35:55 -0500 )edit

answered 2016-08-11 09:37:52 -0500

Arritmic gravatar image

Many times the problem is related to the order of the libraries:

LIBS += -lopencv_imgcodecs -lopencv_objdetect -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_video
LIBS += -L$${_OPENCV_PATH_ANDROID}/sdk/native/3rdparty/libs/armeabi-v7a -ltbb

I need to put "-lopencv_objdetect" before "-lopencv_core"

edit flag offensive delete link more

answered 2013-01-08 07:42:40 -0500

cv::Algorithm class is implemented in core module. You need to add opencv_core to linker library list, i.e. -lopencv_core.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-01-07 20:08:51 -0500

Seen: 3,903 times

Last updated: Aug 11 '16