Makefile opencv
时间: 2023-08-17 11:07:07 浏览: 35
Sure! Here's an example of a Makefile for compiling an OpenCV program:
```makefile
# Compiler
CC := g++
# Compiler flags
CFLAGS := -std=c++11 -Wall
# OpenCV libraries
OPENCV_LIBS := `pkg-config --libs opencv`
# Source files
SRCS := main.cpp
# Object files
OBJS := $(SRCS:.cpp=.o)
# Executable
EXEC := program
all: $(EXEC)
$(EXEC): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $@ $(OPENCV_LIBS)
%.o: %.cpp
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJS) $(EXEC)
```
To use this Makefile, create a file named "Makefile" in the same directory as your source files and copy the above content into it. Make sure you have OpenCV installed on your system.
Then, place your source code file (e.g., `main.cpp`) in the same directory as the Makefile. To compile your program, simply run `make` in the terminal.
This Makefile assumes that you only have one source file (`main.cpp`). If you have multiple source files, you can add them to the `SRCS` variable, separating each file with a space.
Note: This Makefile is just a basic example. You may need to modify it according to your project's specific requirements.