[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:
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
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 missingFind 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
if it fits into a comment, write a comment, and we'll propell it into an answer !
(and no, not the slightest idea why)