Ask Your Question

OpenCV version 3.4 undefined reference to `cv::bgsegm::createBackgroundSubtractorMOG(int, int, double, double)'

asked 2018-02-19 00:04:41 -0500

khaleesi gravatar image

updated 2018-02-19 02:54:32 -0500

Hello everyone, The OpenCV version I'm currently using is OpenCV 3.4 .

I'm trying to compile a sample program from github. But, I'm receiving the following errors:

/tmp/cctdl0lP.o: In function `createBGSubtractorByName(cv::String const&)':
bgfg.cpp:(.text+0xfd): undefined reference to `cv::bgsegm::createBackgroundSubtractorGMG(int, double)'
bgfg.cpp:(.text+0x190): undefined reference to `cv::bgsegm::createBackgroundSubtractorCNT(int, bool, int, bool)'
bgfg.cpp:(.text+0x2b8): undefined reference to `cv::bgsegm::createBackgroundSubtractorMOG(int, int, double, double)'
collect2: error: ld returned 1 exit status

I found the similar problem referred here. And hence I included the following:

#ifdef _DEBUG                   
#pragma comment(lib, "opencv_bgsegm340d.lib") 
#pragma comment(lib, "opencv_bgsegm340.lib")               

Yet, the problem doesn't seem to be solved. Kindly, help.

Thanks in advance.

edit retag flag offensive close merge delete


What is your platform ? May be I'm wrong but pragma comment(lib, is for msvc and error: ld returned 1 exit status is a link error for gcc or mingw?

LBerger gravatar imageLBerger ( 2018-02-19 02:40:02 -0500 )edit

To me it seems your simply linking the wrong libraries in your project settings.... it tells you it cannot find the corresponding function in its linked libraries.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-02-19 03:08:05 -0500 )edit

I just found out that the OpenCV version that I recently installed(i.e. version 3.4.0) doesn't have opencv_bgsegm340.lib. does this mean I haven't installed OpenCV properly, or the version doesn't have it at all?

khaleesi gravatar imagekhaleesi ( 2018-02-19 03:22:26 -0500 )edit

@LBerger the platform I'm working on is g++.

khaleesi gravatar imagekhaleesi ( 2018-02-19 04:37:49 -0500 )edit

g++ lib is libopencv_bgsegm340 ? #pragma comment(lib, " is it a directive for g++?

LBerger gravatar imageLBerger ( 2018-02-19 05:01:11 -0500 )edit

@LBerger well, No. It is a library to include few background subtraction modules such as MOG and GMG. Unfortunately, when I installed the OpenCV 3.4 version, this and few other library did not get copied to the location. I had to make few changes in my Makefile to get over this problem. Anyway, Thanks for your time and help. :)

khaleesi gravatar imagekhaleesi ( 2018-02-19 22:40:47 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-02-21 04:06:05 -0500

The BGSGM module is located in contrib repository because it is unstable. Therefore, you need to make sure your 3.14 version is not prebuilt (does not contain contrib modules at all) and during your build process you have to enable these contributed modules explicitly.

edit flag offensive delete link more


Thanks, @StevenPuttemans.That helped!

khaleesi gravatar imagekhaleesi ( 2018-02-21 21:36:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-02-19 00:04:41 -0500

Seen: 450 times

Last updated: Feb 19 '18