I'm trying to write makefile for opencv file on ubuntu 14.04
Here is example: Makefile to Compile OpenCV Code in C++ on Ubuntu/Linux
If I try yo use it in this form:
CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
% : %.cpp
g++ $(CFLAGS) $(LIBS) -o $@ $<
I get
make: *** No targets. Stop.
If I try
IFLAGS = `pkg-config --cflags opencv`
LFLAGS = `pkg-config --libs opencv`
all: minimal
minimal: minimal.cpp
g++ $(IFLAGS) $(LFLAGS) -o minimal minimal.cpp
I get
g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` -o minimal minimal.cpp
/tmp/ccKWVtBh.o: In function `main':
minimal.cpp:(.text+0x4d): undefined reference to `cv::imread(std::string const&, int)'
minimal.cpp:(.text+0x123): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
minimal.cpp:(.text+0x1a6): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
minimal.cpp:(.text+0x1ce): undefined reference to `cv::waitKey(int)'
/tmp/ccKWVtBh.o: In function `cv::Mat::~Mat()':
minimal.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccKWVtBh.o: In function `cv::Mat::operator=(cv::Mat const&)':
minimal.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccKWVtBh.o: In function `cv::Mat::release()':
minimal.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
/tmp/ccKWVtBh.o: In function `cv::_InputArray::_InputArray<unsigned char>(cv::Mat_<unsigned char> const&)':
minimal.cpp:(.text._ZN2cv11_InputArrayC2IhEERKNS_4Mat_IT_EE[_ZN2cv11_InputArrayC5IhEERKNS_4Mat_IT_EE]+0x17): undefined reference to `vtable for cv::_InputArray'
/tmp/ccKWVtBh.o: In function `cv::Mat_<unsigned char>::operator=(cv::Mat const&)':
minimal.cpp:(.text._ZN2cv4Mat_IhEaSERKNS_3MatE[_ZN2cv4Mat_IhEaSERKNS_3MatE]+0x77): undefined reference to `cv::Mat::reshape(int, int, int const*) const'
minimal.cpp:(.text._ZN2cv4Mat_IhEaSERKNS_3MatE[_ZN2cv4Mat_IhEaSERKNS_3MatE]+0xdd): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/tmp/ccKWVtBh.o: In function `cv::_OutputArray::_OutputArray<unsigned char>(cv::Mat_<unsigned char>&)':
minimal.cpp:(.text._ZN2cv12_OutputArrayC2IhEERNS_4Mat_IT_EE[_ZN2cv12_OutputArrayC5IhEERNS_4Mat_IT_EE]+0x2a): undefined reference to `vtable for cv::_OutputArray'
collect2: error: ld returned 1 exit status
make: *** [minimal] Error 1
But if I use this form it compiles successfully
IFLAGS = `pkg-config --cflags opencv`
LFLAGS = `pkg-config --libs opencv`
all: minimal
minimal: minimal.cpp
g++ $(IFLAGS) -o minimal minimal.cpp $(LFLAGS)
Why standard makefile example don't work for me? What order of libs, includes and *.cpp we should use in makefile?