Makefile 652 B

1234567891011121314151617181920212223242526272829303132333435
  1. # 编译器
  2. CXX = g++
  3. # 编译选项
  4. CXXFLAGS = -std=c++11 -Wall
  5. # OpenCV 库路径和链接库
  6. OPENCV_LIBS = -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_ml
  7. OPENCV_CFLAGS = -I/usr/local/include/opencv4
  8. # 目标可执行文件
  9. TARGET = main
  10. # 源文件
  11. SRCS = src/main.cpp
  12. # 目标文件
  13. OBJS = $(SRCS:.cpp=.o)
  14. # 默认目标
  15. all: $(TARGET)
  16. # 生成可执行文件
  17. $(TARGET): $(OBJS)
  18. $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS) $(OPENCV_LIBS)
  19. # 生成目标文件
  20. %.o: %.cpp
  21. $(CXX) $(CXXFLAGS) $(OPENCV_CFLAGS) -c $< -o $@
  22. # 清理生成的文件
  23. clean:
  24. rm -f $(OBJS) $(TARGET)
  25. .PHONY: all clean