Makefile for c++ program with OpenCV
I tried to compile my program in terminal, here's how I compile it :
g++ $(pkg-config --cflags --libs opencv4) -std=c++11 one.cpp -o one
It works perfectly that way. But now I have several files and would rather use makefile instead, I tried to create makefile for my c++ program, here's my code :
BIN_DIR= .
CC = g++
CFLAGS = -std=c++11
OPENCV = pkg-config --cflags --libs opencv4
LIBS = $(OPENCV)
all: $(BIN_DIR)/one $(BIN_DIR)/two
$(BIN_DIR)/one: one.o
${CC} -o $(BIN_DIR)/one one.o $(LIBS)
$(BIN_DIR)/two: two.o
${CC} -o $(BIN_DIR)/two two.o $(LIBS)
one.o: one.cpp
${CC} $(CFLAGS) -c one.cpp
two.o: two.cpp
${CC} $(CFLAGS) -c two.cpp
clean:
rm -f *.o
rm -f $(BIN_DIR)/one
rm -f $(BIN_DIR)/two
allclean:
rm -f *.o
rm -f $(BIN_DIR)/one
rm -f $(BIN_DIR)/two
rm -f Makefile
But I encounter error "opencv2/opencv.hpp file nout found". But I can compile correctly with the first method. What did I do wrong with my makefile ? thank you