Ask Your Question
0

"undefined reference to ..." OpenCV_3.4.10 on ubuntu 18.04

asked 2020-07-17 09:54:28 -0600

rom_18 gravatar image

updated 2020-07-17 10:09:07 -0600

Hello,

I have errors when I'm trying to compile this program :

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main()
{
    std::cout << "Hello world" << std::endl;
    cv::Mat image = cv::imread("/media/D280-BD55/circleGrid_6x4.jpg", CV_LOAD_IMAGE_COLOR);
}

I have these errors :

g++ main.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc -o main

/tmp/ccyRyEy9.o: In function `main':
main.cpp:(.text+0x6c): undefined reference to `cv::imread(cv::String const&, int)'
/tmp/ccyRyEy9.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4c): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccyRyEy9.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x10): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status

The odd thing is that if I comment the cv::imread() instruction, it works fine.

I tryed a lot of things I found on the web but nothing worked for me

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-07-17 10:32:23 -0600

berak gravatar image

updated 2020-07-17 10:35:00 -0600

cv::imread() is from the imgcodecs module, so you need to add another lib to your cmdline:

g++ main.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -o main

I tryed a lot of things I found on the web

(it was in highgui in older 2.x versions (where your cmdline would have worked) , so make sure to read something recent.)

edit flag offensive delete link more

Comments

Even with this command, I have it doesn't work

rom_18 gravatar imagerom_18 ( 2020-07-17 10:38:48 -0600 )edit

I have it doesn't work

poor problem description ;(

berak gravatar imageberak ( 2020-07-17 10:55:56 -0600 )edit

Sorry, I do my best do describe my problem but I'm not english.

The problem is that I always have the error, even when I add all the necessary libraries.

rom_18 gravatar imagerom_18 ( 2020-07-17 14:26:07 -0600 )edit

Question Tools

Stats

Asked: 2020-07-17 09:54:28 -0600

Seen: 1,353 times

Last updated: Jul 17 '20