---
# System prepended metadata

title: Makefile

---

# OpenCV Compiling

### Command-line
```shell
g++ *.cpp -o output_name `pkg-config --cflags --libs opencv4`
```

### Makefile

```shell=
# Define target file and source files
TARGET = test
SRCS = $(wildcard *.cpp)

# Compiler and its options
CXX = g++
CXXFLAGS = `pkg-config --cflags opencv4`
LDFLAGS = `pkg-config --libs opencv4`

# Rule: Compile the target
$(TARGET): $(SRCS)
	$(CXX) $(CXXFLAGS) -o $(TARGET) $(SRCS) $(LDFLAGS)

# Rule: Clean up generated files
clean:
	rm -f $(TARGET)

run: $(TARGET)
	./$(TARGET)
    
# Alaways rebuild
.PHONY: $(TARGET) clean
```

