I am using a make file to compile a c++ opencv 2.4.3 program here is my code.
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main (int argc, char** argv)
{
if(argc!=2)
{
cout<<" Usage: display_image ImageToLoad_Zoomed_and displayed "<<endl;
return -1;
}
Mat image;
image =imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE );
if(!image.data)
{
cout<< "Could not open or find the image"<<endl;
return -1;
}
cout<<"Show Image"<<endl;
namedWindow("Display window", WINDOW_AUTOSIZE);
imshow("Display window ", image);
waitKey(0);
return 0;
}
makefile
# compiler
CC :=g++
# include files
CFLAGS :=`pkg-config --cflags opencv`
LDFLAGS :=`pkg-config --libs opencv`
# compile all c++ files in dir
SOURCES :=$(*.cpp)
# C++ files .cpp removed file is executable
EXECUTABLE :=$(SOURCES:.cpp=)
all:$(EXECUTABLE)
$(EXECUTABLE):$(SOURCES)
$(CC) $< $(LDFLAGS) $(CFLAGS) -o $@
clean:
rm -rf $(EXECUTABLE)
Here is How I compile
g++ display.cpp pkg-config opencv --cflags
pkg-config opencv --libs
-o display
I get the popular error:
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccAbu9Kb.o
"cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccAbu9Kb.o
"cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in ccAbu9Kb.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I tried to fix it by googling but I couldn't. Any help?