Ask Your Question
0

[opencv2.4] g++ imread linker error

asked 2016-01-23 13:20:24 -0600

pietrko gravatar image

I got linker error trying to compile this simple code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <string>

using namespace cv;

int main(int argc, char** argv) {

    std::string filename = argv[1];
    Mat A;
    A = imread(filename);
    return 0;
}

Here is the makefile:

CXX=g++
LDFLAGS=`pkg-config --libs opencv`
CXXFLAGS=-Wall -v
CXXFLAGS+=`pkg-config --cflags opencv`


cam_calibration.o : cam_calibration.cxx
    $(CXX) $(CXXFLAGS) $(LDFLAGS) cam_calibration.cxx

clean : 
    rm *.o

The error is following (after issuing "make"):

/tmp/cccbWfsF.o: In function `main':
cam_calibration.cxx:(.text+0x6b): undefined reference to `cv::imread(std::string const&, int)'
collect2: error: ld returned 1 exit status

What is wrong with this code? I'm using Archlinux, g++ (5.2.0) and have all the opencv libraries in version 2.4

edit retag flag offensive close merge delete

Comments

what is the output of pkg-config --libs opencv ? try to run it on a console.

in the end, -l opencv_highgui seems to be missing

berak gravatar imageberak ( 2016-01-24 00:48:22 -0600 )edit

Find the reason it was gcc (can't post answer I'm new -- need to wait 2 days), here is output you asked, highgui is not missing;

Thanks for interest - if you have any idea why gcc 5.3.x is ok, and gcc 5.2.0 gives and error please share.

-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -ltbb -lGL -lGLU -lrt -lpthread -lm -ldl

pietrko gravatar imagepietrko ( 2016-01-24 06:07:06 -0600 )edit

if it fits into a comment, write a comment, and we'll propell it into an answer !

(and no, not the slightest idea why)

berak gravatar imageberak ( 2016-01-24 06:17:28 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2016-01-24 06:20:36 -0600

pietrko gravatar image

updated 2016-01-24 06:21:37 -0600

FIXED: It was gcc. For some magical, unknown reason gcc 5.2.0 can't link code I've posted properly, whereas with gcc 5.3.x everything is ok. Mark as fixed.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-23 13:20:24 -0600

Seen: 519 times

Last updated: Jan 23 '16