Ask Your Question
1

undefined reference to imread

asked 2019-11-12 16:32:16 -0600

trolstover gravatar image

updated 2019-11-13 01:36:22 -0600

berak gravatar image

I have openCV installed on server, and basic program

#include <iostream>

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

using namespace cv;
using namespace std;


int main()
{
    Mat RGBImage;

    RGBImage =imread("uno.png");
   cout << RGBImage.size();
    return 0;
}

and compillin it with

g++ main.cpp -I/opt/robots/pepper/ctc-linux64-atom-2.5.10.7/opencv2/include/

but i recieve error:

/tmp/ccqypB17.o: In function main': main.cpp:(.text+0x6d): undefined reference to cv::imread(std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, int)' /tmp/ccqypB17.o: In function cv::Mat::~Mat()': main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to cv::fastFree(void*)' /tmp/ccqypB17.o: In function cv::Mat::operator=(cv::Mat const&)': main.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x117): undefined reference to cv::Mat::copySize(cv::Mat const&)' /tmp/ccqypB17.o: In function cv::Mat::release()': main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to cv::Mat::deallocate()' collect2: error: ld returned 1 exit status

Why is this happening?

if o omite code and just compile it with

#include <iostream>

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

using namespace cv;
using namespace std;


int main()
{

    return 0;
}

it works fine.

i tried usin

g++ main.cpp -I/opt/robots/pepper/ctc-linux64-atom-2.5.10.7/opencv2/include/ -L/opt/robots/pepper/ctc-linux64-atom-2.5.10.7/opencv2/lib

but error is same..

Why is this happening? Am i compilinng with wrong commands? I am tryin to make it work for over 2 weeks and still unsucessfully.. please help :(

edit retag flag offensive close merge delete

Comments

Yeh this fix problem, more precisely add "-loopencv_core" or any lib like "-lopencv_(THE LIB OPENCV NAME HERE)

neto gravatar imageneto ( 2020-02-29 21:00:25 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2019-11-13 01:23:45 -0600

berak gravatar image

updated 2019-11-13 01:26:05 -0600

undefined reference

means, you're not linking some required lib,

(in your case, ALL of the opencv libs are missing from the cmdline !)

try again with:

g++ main.cpp -I/opt/robots/pepper/ctc-linux64-atom-2.5.10.7/opencv2/include/ -L/opt/robots/pepper/ctc-linux64-atom-2.5.10.7/opencv2/lib -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_videoio

(this should get you through most of the tutorial code)

edit flag offensive delete link more
-1

answered 2019-11-12 20:35:38 -0600

Gourav gravatar image

Imread takes two arguments
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
This should fix problem

edit flag offensive delete link more

Comments

no this won't fix the problem, you did not understand the question.

berak gravatar imageberak ( 2019-11-13 01:24:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-11-12 16:32:16 -0600

Seen: 12,011 times

Last updated: Nov 13 '19