Makefile for c++ program with OpenCV

asked 2019-01-29 14:53:55 -0500

raisa_ gravatar image

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 :

CC = g++
CFLAGS = -std=c++11

OPENCV = pkg-config --cflags --libs opencv4

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

    rm -f *.o
    rm -f $(BIN_DIR)/one
    rm -f $(BIN_DIR)/two

    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

edit retag flag offensive close merge delete