Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[opencv2.4] g++ imread linker error

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:

LDFLAGS=`pkg-config --libs opencv`
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