LoginSignup
12

More than 5 years have passed since last update.

OpenCVのC++コードをMacでmakeする際のMakefile

Last updated at Posted at 2014-10-13

コード

# コンパイラを指定
CC :=g++
# インクルードファイル等
CFLAGS :=`pkg-config opencv --cflags` `pkg-config opencv --libs`
LDFLAGS :=
# ディレクトリ内の全てのC++ファイルをコンパイル
SOURCES :=$(wildcard *.cpp)
# C++ファイルの.cppをとったものを実行ファイルの名前とする
EXECUTABLE :=$(SOURCES:.cpp=)

all:$(EXECUTABLE)

$(EXECUTABLE):$(SOURCES)
    $(CC) $< $(LDFLAGS) $(CFLAGS) -o $@

clean:
    rm -rf $(EXECUTABLE)

使用例

$ ls
Makefile  mat.cpp
$ make
g++ mat.cpp  `pkg-config opencv --cflags` `pkg-config opencv --libs` -o mat
$ ./mat

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12