SlideShare a Scribd company logo
1 of 59
Download to read offline
ソフトウェア工学
nビルド
• コンパイルオプション,ビルド,make,Makefile,cmake,
pkg-config
玉木徹(名工大)
ビルド
ビルドとは
nコードをコンパイルして実行形式ファイルなどを作成すること
• C, C++など
コンパイラ リンカ
ソース
ファイル
オブジェクト
ファイル
静的ライブラリ
(*.a)
実行
ファイル
静的
リンク
コンパイル
実行
ファイル
共有ライブラリ (*.so)
DLL
動的
リンク
ビルド 実行
ヘッダファイル
(*.h)
静的
リンク
ツールによるビルドの自動化
nビルドは複雑になる
• 多数のファイル
• 多数の生成される実行ファイル
• ドキュメントも生成
• 手順が煩雑になり,人手ではエラーも発生
nビルドツールの利点
• ビルドが自動化できる
• C/C++などの大規模プロダクト
• 様々な手順が自動化できる
• Pythonなどスクリプト言語でも自動化するべき手順はある
• ユニットテスト,回帰テスト
• コードスタイルのチェック
Cコンパイルの基礎
nコンパイラ:gcc
gcc main.c
main.c a.out
gcc main.c -o main
main.c main
gcc main.c myfunc.c -o main
myfunc.c main
main.c
コンパイルする
ファイル名
ファイル名を指定し
ないとa.outになる
コンパイルするファイ
ル名は複数でも良い
-oで生成されるファ
イル名を指定
複数ファイルのコンパイル
gcc main.c myfunc.c -o main -lm
myfunc.c main
main.c
libm.a
-lでリンクするライブラリ名を指定
「-lm」なら「libm.a」というファ
イル名のライブラリをリンクする
システムデフォルトのライブラリパス
(一般的に/usr/lib)にlibm.aがあるか
ら,場所を指定しなくてよい
math.h
オブジェクトファイルにしてからリンク
gcc -c main.c
gcc -c myfunc.c
gcc main.o myfunc.o -o main -lm
myfunc.o main
main.o
libm.a
myfunc.c
main.c
-cでコンパイル
するファイルを
指定
リンクするオブジェクトファイルを指定
gccがリンカを
呼び出している
math.h
ファイルが数百〜数千個
もあったら,オブジェク
トファイルのリンクは速
くてもコンパイルは遅
い...
外部ライブラリの利用
gcc -c main.c -I/usr/local/include/opencv2
gcc -c myfunc.c -I/usr/local/include
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl -lopencv
myfunc.o main
main.o
libm.a
myfunc.c
main.c
pcl.h
cv.h libopencv.a
include include
libpcl.a
/usr/local/include
/usr/local/include/opencv2 /usr/local/lib /usr/local/lib/cv2
手動ビルド
は手間!
ヘッダファイル
のパスは特殊
ライブラリファイ
ルのパスも特殊
注:架空のビルドの
例です
外部ライブラリの利用
gcc -c main.c -I/usr/local/include/opencv2
gcc -c myfunc.c -I/usr/local/include
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl -lopencv
-Iでヘッダファイルのパスを指定
-Lでライブラリのパスを指定
libpcl.aと
libopencv.aという名前
のファイルをリンク
makeとMakefile
makeとは
n自動ビルドのコマンドラインツール
• 古くから利用されている
• 設定ファイルMakefileの内容に従ってコマンドを実行
• ビルド(コンパイル)以外にも使える
docker composeを利用する
起動する
$ cd 10_01_make
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
コードをチェックアウト
$ git checkout v0.1
ビルドコマンドをMakefileに変換
gcc -c main.c -I/usr/local/include/opencv2
gcc -c myfunc.c -I/usr/local/include
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl -lopencv
注:架空のビルドの
例です
main: main.o myfunc.o
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl -opencv
main.o: main.c
gcc -c main.c -I/usr/local/include/opencv2
myfunc.o: myfunc.c
gcc -c myfunc.c -I/usr/local/include
.PHONY: all clean
all: main
clean:
rm -f main main.o myfunc.o
Makefileの基本
nルール=ターゲット,依存ファイル,コマンド
• コマンドラインで「make ターゲット名」が実行されると
• ターゲットファイルがなければ
• もしくは依存ファイルが書き換わったら
• (タイムスタンプを比較)
• コマンドが実行実行され
• ターゲットが生成される
ターゲット
(生成されるファ
イル名)
依存ファイル
実行されるコマンド
ルール
makeコマンドの引
数にターゲットを
指定
(2回目)
main.cが変更され
ていないので
何もし
ない
main.o: main.c
gcc -c main.c -I/usr/local/include/opencv2
$ docker compose exec mygcc make main.o
gcc -c main.c -I/usr/local/include/opencv2
$
$ docker compose exec mygcc make main.o
make: 'main.o' is up to date.
$
Makefileのルールの見方
main: main.o myfunc.o
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl -
main.o: main.c
gcc -c main.c -I/usr/local/include/opencv2
myfunc.o: myfunc.c
gcc -c myfunc.c -I/usr/local/include
myfunc.cから
myfunc.oを生成
main.cからmain.o
を生成
main.oとmyfunc.o
からmainを生成
注意!この空白は「タブ1つ」です.半角
スペースではエラーになります!
(makefileのつまづきどころ)
make all, make clean
phony(ダミー)のダーゲッ
ト:allとcleanはファイルでな
い
“make all”で,mainを生成する
という意味のターゲット
“make clean”で,不要なファ
イルを削除するという意味の
ターゲット
ファイル名ではないターゲット
にはphony targetを利用する
.PHONY: all clean
all: main
clean:
rm -f main main.o myfunc.o
docker composeを利用する
起動する
$ cd 10_01_make
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
コードをチェックアウト
$ git checkout main
main: main.o myfunc.o
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl
main.o: main.c
gcc -c main.c -I/usr/local/include/opencv2
myfunc.o: myfunc.c
gcc -c myfunc.c -I/usr/local/include
ターゲットを分ける必要性
n更新が必要なファイルだけをコンパイルする
• ファイルが数個の場合
• 毎回全部一度にコンパイルすればよい
• ファイルが数千個の場合
• 修正したファイルだけをコンパイルしたい
• コンパイルには時間がかかる
• オブジェクトファイルをリンクするだけなら短時間で済む
myfunc.cは変更さ
れてないのでコン
パイルしない
main.cが変更され
たらコンパイル
例
main.oが更新され
たのでこのルール
を実行
%パターンマッチ
n多数のファイルに個別の
ルールを記述するのは手間
• 「*.c」というファイルから
「*.o」を作成する,という
ルールを一括で書きたい
• Makefileではワイルドカー
ドに「%」を用いる
• 「%.c」なら「*.c」とい
う名前を持つ各ファイル
しかし-Iの指定を忘れている
main.o: main.c
gcc -c main.c -I/usr/local/include/opencv2
myfunc.o: myfunc.c
gcc -c myfunc.c -I/usr/local/include
%.o: %.c
gcc $(CFLAGS) -c $< -o $@
もし依存ファイルが
main.cならターゲット
はmain.oになる
パターン「*.c」に一致
するファイル
(たとえばmain.c)
ターゲット
ファイル名
(main.o)に
変換される
依存ファイル名
(main.c)に変
換される
変数を使う
n変数宣言と代入
• 変数名 := 内容
n変数の利用
• $(変数名)
変数INCLUDEに設定
変数CFLAGSに
INCLUDEを追加
オプションにCFLAGS
を追加
通常CFLAGSは
Cコンパイラの
デフォルトオプ
ションが入って
いる変数
(だから上書き
しない)
バックスラッ
シュで改行以
降も続く
C++なら
CXXFLAGS
INCLUDE := -I/usr/local/include/opencv2 ¥
-I/usr/local/include
CFLAGS := $(INCLUDE) $(CFLAGS)
%.o: %.c
gcc $(CFLAGS) -c $< -o $@
main.o: main.c
gcc -c main.c -I/usr/local/include/opencv2
myfunc.o: myfunc.c
gcc -c myfunc.c -I/usr/local/include
OBJS = main.o myfunc.o
main: $(OBJS)
gcc $(OBJS) -o main $(LDFLAGS)
LIBS := -lm -lpcl -lopencv
LIBDIRS := -L/usr/local/lib -L/usr/local/lib/cv2
LDFLAGS := $(LIBDIRS) $(LIBS) $(LDFLAGS)
変数を使う
オプションに
LDFLAGSを追加
*.oファイルをOBJSで
まとめる
リンクするライブラリ
ライブラリのあ
るディレクトリ
変数LDLAGSにLIBSと
LIBDIRSを追加
通常LDFLAGSはリンカのデフォルトオプショ
ンが入っている変数(だから上書きしない)
main: main.o myfunc.o
gcc main.o myfunc.o -o main -lm -L/usr/local/lib -L/usr/local/lib/cv2 -lpcl -opencv
OBJS = main.o myfunc.o
main: $(OBJS)
gcc $(OBJS) -o main $(LDFLAGS)
LIBS := -lm -lpcl -lopencv
LIBDIRS := -L/usr/local/lib -L/usr/local/lib/cv2
LDFLAGS := $(LIBDIRS) $(LIBS) $(LDFLAGS)
INCLUDE := -I/usr/local/include/opencv2 ¥
-I/usr/local/include
CFLAGS := $(INCLUDE) $(CFLAGS)
%.o: %.c
gcc $(CFLAGS) -c $< -o $@
.PHONY: all clean
all: main
clean:
rm -f main $(OBJS)
整理したMakefile
makeの実行結果
ファイルが増えたらこ
こに追加するだけ
注:架空のビルドの
例です
$ docker compose exec mygcc make
gcc -I/usr/local/include/opencv2 -I/usr/local/include -c main.c -o main.o
gcc -I/usr/local/include/opencv2 -I/usr/local/include -c myfunc.c -o myfunc.o
gcc main.o myfunc.o -o main -L/usr/local/lib -L/usr/local/lib/cv2 -lm -lpcl -lopencv
$
いろいろな応用
docker composeを利用する
起動する
$ cd 10_02_make_latex
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
コンパイル以外のMakefileの例
n複数のlatexファイルをplatexでコンパイル
• メインファイルはthesis.tex
• それが他のファイルをインクルードしている
• ルール
• texファイルのどれか1つでも修正されたらplatexを実行
• dviができるのでそれをdvipdfmxでpdfへ変換
n注意
• 現実ではlatexmkを使おう TEXS = thesis.tex intro.tex method.tex experiment.tex
thesis.pdf: $(TEXS)
platex thesis.tex
dvipdfmx thesis.dvi
.PHONY: all clean
all: thesis.pdf
clean:
rm -f thesis.pdf thesis.dvi *.aux *.toc *.log *.fls *.f
makeでlatexコンパイル
platex thesis.tex
dvipdfmx thesis.dvi
$ docker compose exec mylatex make
platex thesis.tex
This is e-pTeX, Version 3.141592653-p4.1.0-230214-2.6 (utf8.euc) (Te
restricted ¥write18 enabled.
entering extended mode
(./thesis.tex(guessed encoding #3: UTF-8 = utf8)
pLaTeX2e <2023-02-14>+1 (based on LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-05-05>
(/usr/local/texlive/2023/texmf-dist/tex/platex/base/jarticle.cls(gue
Document Class: jarticle 2020/09/30 v1.8f Standard pLaTeX class
(/usr/local/texlive/2023/texmf-dist/tex/platex/base/jsize10.clo(gues
(/usr/local/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-dv
No file thesis.aux.
(./intro.tex(guessed encoding #6: UTF-8 = utf8)) (./method.tex(guess
Output written on thesis.dvi (1 page, 840 bytes).
Transcript written on thesis.log.
dvipdfmx thesis.dvi
thesis.dvi -> thesis.pdf
[1]
15976 bytes written
$
よくあるmakeの使い方
nmake all または make
• すべてビルド
nmake test
• テストコードを実行
nmake debug
• デバッグオプション(-g)をつけ
てコンパイル
nmake doc
• ドキュメントを作成
nmake clean
• 生成されたファイルを削除
nsudo make install
• システムにインストール
• (通常は)root権限が必要
nsudo make uninstall
• インストールしたファイルをシス
テムから削除
• (ファイルを記憶しておくなど特
殊処理が必要)
docker composeを利用する
起動する
$ cd 10_03_make_test
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
.PHONY: clean test coverage
test:
python -m unittest test_compute.py
coverage:
coverage run test_compute.py
coverage report
coverage html
coverage xml
clean:
rm -rf *.pyc __pycache__/
rm -rf htmlcov/ coverage.xml .coverage
$ docker compose exec mypython make test
python -m unittest test_compute.py
..............
----------------------------------------
Ran 14 tests in 0.000s
OK
$ docker compose exec mypython make coverage
coverage run test_compute.py
..............
-----------------------------------------
Ran 14 tests in 0.001s
OK
coverage report
Name Stmts Miss Cover
-------------------------------------
compute.py 29 2 93%
test_add.py 26 1 96%
test_compute.py 5 0 100%
test_mult.py 26 1 96%
-------------------------------------
TOTAL 86 4 95%
coverage html
Wrote HTML report to htmlcov/index.html
coverage xml
Wrote XML report to coverage.xml
$ docker compose exec mypython make clean
rm -rf *.pyc __pycache__/
rm -rf htmlcov/ coverage.xml .coverage
$
make testでテストコードを実行する例
テスト実行
カバレッ
ジ計測
不要ファイルの削除
Makefile maker
docker composeを利用する
起動する
$ cd 10_04_cmake
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
OBJS = main.o myfunc.o
main: $(OBJS)
gcc $(OBJS) -o main $(LDFLAGS)
LIBS := -lm -lpcl -lopencv
LIBDIRS := -L/usr/local/lib -L/usr/local/lib/cv2
LDFLAGS := $(LIBDIRS) $(LIBS) $(LDFLAGS)
INCLUDE := -I/usr/local/include/opencv2 ¥
-I/usr/local/include
CFLAGS := $(INCLUDE) $(CFLAGS)
%.o: %.c
gcc $(CFLAGS) -c $< -o $@
Makefileは環境依存
コンパイラ
がgccではな
くccやclang
の場合もあ
る
ライブラリ
がインス
トールされ
た場所は環
境依存
ヘッダファ
イルがイン
ストールさ
れた場所も
環境依存
ライブラリ名す
ら環境によって
微妙に異なるこ
ともある
クロスプラットフォーム・ビルド
n環境に応じてビルドする各種ツール
• Makefile生成型
• CMake, autotools, etc
• Makefileを使わないものもある
• https://en.wikipedia.org/wiki/List_of_build_automation_software
GNU autotools
nconfigureスクリプトからMakefileを生成
• 手順
./configure
make all
sudo make install
n複数のツール群
• aclocale, autoheader, autoconf, automake, …
• configureスクリプトの生成までは長い道程
n使っているOSS
• Apache
• FFmpeg
• Perl
• etc
GNU autoconf and automake process for generating
makefilesJdthood - Own work, based
on https://commons.wikimedia.org/wiki/File:Autoconf.svg
CC BY-SA 3.0
CMake
n設定ファイルCMakeLists.txtから色々と生成できる
• Makefile, Xcodeプロジェクトファイル,Visual Studioプロジェクトファイル
• GUI版もある
n現在多数のOSSで使われている
• OpenCV, PCL, ROS
• LLVM/Clang, ITK/VTK, KDE
• Blender
• etc
Logo di CmakeCmake team. The original uploader was Francesco
Betti Sorbelli at Italian Wikipedia.. Vectorized by Magasjukur2 -
File:Cmake.jpg
CC BY 2.0
ディレクトリ構成
n トップディレクトリ
• 設定ファイル
• プロジェクト全体のCMakeLists.txt
• 各種ディレクトリ
n srcディレクトリ
• 各種ソースがある
• 個別のCMakeLists.txt
• ソースファイル
n buildディレクトリ
• 最初は存在しない.cmakeで作成される
• ソースがここにコピーされて,ビルドが実行される
• ここでmakeを実行
• 不要になれば削除
プロジェクト全体のCMakeLists.txt
cmakeの設定
srcディレクト
リを追加
• プロジェクト名を「my_main」に設定
• 使用言語はC++とCを使うという宣言
これ
cmake_minimum_required(VERSION 3.0)
project(my_main CXX C)
add_subdirectory(src)
個別のCMakeLists.txt
作成する実行ファイル名を「my_main」に
指定.続いてソースファイルを指定
(main.cppとmyfunc.cの2つ)
プロジェクトにリンクするライ
ブラリを指定(ここではlibm.a
なので「m」とする)
「OpenCV」という名前のパッ
ケージを追加(REQUIREDは必
須という指定)
「OpenCV」パッケージを追加し
たら定義される変数を使って,
リンクするライブラリを指定
これ
cmake_minimum_required(VERSION 3.0)
add_executable(my_main main.cpp myfunc.c)
target_link_libraries(my_main m)
find_package(OpenCV REQUIRED)
target_link_libraries(my_main ${OpenCV_LIBS})
$ docker compose exec myopencv cmake -S src/ -B build/
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found version "4.5.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/build
$
cmakeを実行 cmake
が作成
-Sでソースファイルの
パスを指定
-Bでビルド用のパスを
指定
Cコンパイラを
自動検索
C++コンパイ
ラを自動検索
パッケージを
自動検索
$ docker compose exec myopencv cmake --build build/
Scanning dependencies of target my_main
[ 33%] Building CXX object CMakeFiles/my_main.dir/main.cpp.o
[ 66%] Building C object CMakeFiles/my_main.dir/myfunc.c.o
[100%] Linking CXX executable my_main
[100%] Built target my_main
$ docker compose exec myopencv build/my_main
[1.119730324797946, 0, 0;
0, 1, 0;
0, 0, 1]
$
cmakeでビルド
nbuild/以下でビルドされる --buildでビルド用パ
スを指定して,そこで
ビルド
ビルド用パスに生
成されたバイナリ
を実行してみる
$ docker compose exec myopencv make -C build/
make: Entering directory '/mnt/build'
make[1]: Entering directory '/mnt/build'
make[2]: Entering directory '/mnt/build'
Scanning dependencies of target my_main
make[2]: Leaving directory '/mnt/build'
make[2]: Entering directory '/mnt/build'
[ 33%] Building CXX object CMakeFiles/my_main.dir/main.cpp.o
[ 66%] Building C object CMakeFiles/my_main.dir/myfunc.c.o
[100%] Linking CXX executable my_main
make[2]: Leaving directory '/mnt/build'
[100%] Built target my_main
make[1]: Leaving directory '/mnt/build'
make: Leaving directory '/mnt/build'
$
makeでビルド
nmakeでもビルドできる
• build/以下にMakefileが生成されている
-Cで指定したパスに移動し
てmakeを実行する
もしくはこれでもよい 注:docker-composeで
はうまく動かない
(フォルダのマウント
設定のため)
$ cd build
$ make
makeでビルド
nmakeでもビルドできる
• build/以下にMakefileが生成されている
• cdでbuild/に移動してmake
もしくはこれでもよい 注:docker-composeで
はうまく動かない
(フォルダのマウント
設定のため)
$ cd build
$ make
$ docker compose exec myopencv bash
root@c8e10fd36f55:/mnt# cd build
root@c8e10fd36f55:/mnt/build# make
[ 33%] Building CXX object CMakeFiles/my_main.dir/main.cpp.o
[ 66%] Building C object CMakeFiles/my_main.dir/myfunc.c.o
[100%] Linking CXX executable my_main
[100%] Built target my_main
root@c8e10fd36f55:/mnt/build#
VScodeでCMake
VSodeをコンテナにattachするのを忘れないように
cmake tools
で検索して
インストール
構成するかを聞
かれたらyes
もしくはコマンドパ
レットから自分で構成
を選択して
gccを選ぶ
cmake
実行
cmake --build 実行
make clean
make clean
cmake --build
cmake
cmakeタブ
へ行くと
./build/src/以下にでき
る(構成による)
pkg-config
パッケージ設定ファイルの管理ツール
docker composeを利用する
起動する
$ cd 10_05_pkg-config
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
cmakeファイル:CMake用の設定管理
cmakeはどこからパッケージ
情報を得ているのか?
このディレクトリにあ
る.cmakeから
ライブラリ名やパ
スは直接調べるの
は難しい
root@96d155f90277:/mnt# ls -la /usr/local/lib/cmake/opencv4/
total 76
drwxr-xr-x 2 root root 4096 Dec 23 2020 .
drwxr-xr-x 3 root root 4096 Dec 23 2020 ..
-rw-r--r-- 1 root root 418 Dec 23 2020 OpenCVConfig-version.cmake
-rw-r--r-- 1 root root 15324 Dec 23 2020 OpenCVConfig.cmake
-rw-r--r-- 1 root root 28259 Dec 23 2020 OpenCVModules-release.cmake
-rw-r--r-- 1 root root 17330 Dec 23 2020 OpenCVModules.cmake
root@96d155f90277:/mnt#
cmake_minimum_required(VERSION 3.0)
add_executable(my_main main.cpp myfunc.c)
target_link_libraries(my_main m)
find_package(OpenCV REQUIRED)
target_link_libraries(my_main ${OpenCV_LIBS})
$ docker compose exec myopencv pkg-config --cflags opencv4
-I/usr/local/include/opencv4
$
$ docker compose exec myopencv pkg-config --libs opencv4
-L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_
bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lo
pencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_
img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality
-lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lo
pencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv
_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopenc
v_plot -lopencv_videostab -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -
lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv
_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_phot
o -lopencv_imgproc -lopencv_core
pkg-config:パッケージ設定の管理
nパッケージの設定情報が管理されている
• CMakeとは無関係
nビルド用の情報
• ヘッダファイルのパス
• ライブラリ名とそのパス
--cflagsで指定したパッケージを
ビルドするためのCFLAGS(-Iオプ
ション)を表示
--libsで指定したパッケージをリ
ンクするためのライブラリオプショ
ンを表示(-Lと-l)
pkg-configの設定ファイル
nパッケージの設定情報が管理されている
• CMakeとは無関係
nビルド用の情報
• ヘッダファイルのパス
• ライブラリ名とそのパス
pkg-configはどこからパッケージ
情報を得ているのか?
このディレクトリにあ
る.pcから
root@96d155f90277:/mnt# ls -la /usr/local/lib/pkgconfig/
total 20
drwxr-xr-x 1 root root 4096 Dec 23 2020 .
drwxr-xr-x 1 root root 4096 Dec 23 2020 ..
-rw-r--r-- 1 root root 1245 Dec 23 2020 opencv4.pc
-rw-r--r-- 1 root root 294 Dec 11 2020 python-3.7.pc
lrwxrwxrwx 1 root root 13 Dec 11 2020 python-3.7m.pc -> python-3.7.pc
lrwxrwxrwx 1 root root 13 Dec 11 2020 python3.pc -> python-3.7.pc
root@96d155f90277:/mnt#
$ docker compose exec myopencv pkg-config --list-all
zlib zlib - zlib compression library
gio-unix-2.0 GIO unix specific APIs - unix specific headers for glib I/O librar
cairo-xcb cairo-xcb - XCB surface backend for cairo graphics library
applewmproto AppleWMProto - AppleWM extension headers
gio-2.0 GIO - glib I/O library
...
pango Pango - Internationalized text handling
uuid uuid - Universally unique id library
opencv4 OpenCV - Open Source Computer Vision Library
python-3.7m Python - Python library
presentproto PresentProto - Present extension headers
...
パッケージ一覧の取得
n指定するパッケージ名
• パッケージ名一覧を取得
pkg-configが管理しているパッケー
ジ一覧を表示
pkg-configを利用したMakefile
注:架空のビルドの
例です
pkg-configを使う場合
pkg-configを使わない場合
OBJS = main.o myfunc.o
main: $(OBJS)
gcc $(OBJS) -o main $(LDFLAGS)
LIBS := -lm -lpcl -lopencv
LIBDIRS := -L/usr/local/lib -L/usr/local/lib/cv2
LDFLAGS := $(LIBDIRS) $(LIBS) $(LDFLAGS)
INCLUDE := -I/usr/local/include/opencv2 ¥
-I/usr/local/include
CFLAGS := $(INCLUDE) $(CFLAGS)
%.o: %.c
gcc $(CFLAGS) -c $< -o $@
.PHONY: all clean
all: main
clean:
rm -f main $(OBJS)
OBJS = main.o myfunc.o
main: $(OBJS)
gcc $(OBJS) -o main $(LDFLAGS)
LDFLAGS := `pkg-config --libs opencv4` $(LDFLAGS) -lm
CFLAGS := `pkg-config --cflags opencv4` $(CFLAGS)
%.o: %.c
gcc $(CFLAGS) -c $< -o $@
.PHONY: all clean
all: main
clean:
rm -f main $(OBJS)
IDEの設定
XcodeでもVisual Studioでもサーチパスの設定は必須
Microsoft Visual Studio
https://docs.microsoft.com/ja-jp/cpp/build/working-with-
project-properties?view=msvc-160
コンパイラとビルドのプロパティを設定する
2019/07/17
Apple Xcode
https://stackoverflow.com/questi
ons/14134064/how-to-set-
include-path-in-xcode-project
How to set include path in xcode
project
課題
nC/C++の簡単なコードのコンパイルを行う
• Makefileを書き,makeでビルド,実行する
• CmakeList.txtを書き,cmakeで構成,ビルド,実行する
想定試験問題
nビルドとは何かを説明せよ
nビルドの自動化の重要性を説明せよ
nMakefile/makeの利点を述べよ
n簡単なビルドのMakefileを書け
ngccにおける-I, -L, -l, -oのオプションの意味を述べよ
nMakefileの%パターンマッチとは何か
nCmakeとは何か,makeに対する優位性を述べよ
npkg-configを使って何が調べられるのかを説明せよ

More Related Content

Similar to ソフトウェア工学2023 14 ビルド

Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話Masahito Zembutsu
 
いまさら聞けないRake入門
いまさら聞けないRake入門いまさら聞けないRake入門
いまさら聞けないRake入門Tomoya Kawanishi
 
Wasm blazor and wasi 2
Wasm blazor and wasi 2Wasm blazor and wasi 2
Wasm blazor and wasi 2Takao Tetsuro
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成shigeki_ohtsu
 
継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキング継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキングTakayuki Kondou
 
Bossan dentoo
Bossan dentooBossan dentoo
Bossan dentookubo39
 
20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)Yoshifumi Yamaguchi
 
第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西Masahide Yamamoto
 
Nodejuku01 ohtsu
Nodejuku01 ohtsuNodejuku01 ohtsu
Nodejuku01 ohtsuNanha Park
 
Linuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くLinuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くTetsuyuki Kobayashi
 
ソースコードリーディングの基礎
ソースコードリーディングの基礎ソースコードリーディングの基礎
ソースコードリーディングの基礎hogemuta
 
Sphinxでドキュメントを書こう
Sphinxでドキュメントを書こうSphinxでドキュメントを書こう
Sphinxでドキュメントを書こうKazufumi Ohkawa
 
ソフトウェア工学2023 07 バージョン管理
ソフトウェア工学2023 07 バージョン管理ソフトウェア工学2023 07 バージョン管理
ソフトウェア工学2023 07 バージョン管理Toru Tamaki
 
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...JUNICHI YOSHISE
 
Eclipse xtext 紹介
Eclipse xtext 紹介Eclipse xtext 紹介
Eclipse xtext 紹介Akira Tanaka
 
Ossで作成するチーム開発環境
Ossで作成するチーム開発環境Ossで作成するチーム開発環境
Ossで作成するチーム開発環境Tadahiro Ishisaka
 
CouchDB JP & BigCouch
CouchDB JP & BigCouchCouchDB JP & BigCouch
CouchDB JP & BigCouchYohei Sasaki
 
CMake multiplatform build-tool
CMake multiplatform build-toolCMake multiplatform build-tool
CMake multiplatform build-toolNaruto TAKAHASHI
 

Similar to ソフトウェア工学2023 14 ビルド (20)

Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話
 
いまさら聞けないRake入門
いまさら聞けないRake入門いまさら聞けないRake入門
いまさら聞けないRake入門
 
Wasm blazor and wasi 2
Wasm blazor and wasi 2Wasm blazor and wasi 2
Wasm blazor and wasi 2
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成
 
継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキング継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキング
 
How to run P4 BMv2
How to run P4 BMv2How to run P4 BMv2
How to run P4 BMv2
 
Bossan dentoo
Bossan dentooBossan dentoo
Bossan dentoo
 
20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)20130228 Goノススメ(BPStudy #66)
20130228 Goノススメ(BPStudy #66)
 
第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西
 
Nodejuku01 ohtsu
Nodejuku01 ohtsuNodejuku01 ohtsu
Nodejuku01 ohtsu
 
Linuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くLinuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書く
 
ソースコードリーディングの基礎
ソースコードリーディングの基礎ソースコードリーディングの基礎
ソースコードリーディングの基礎
 
Sphinxでドキュメントを書こう
Sphinxでドキュメントを書こうSphinxでドキュメントを書こう
Sphinxでドキュメントを書こう
 
Sphinx/reST
Sphinx/reSTSphinx/reST
Sphinx/reST
 
ソフトウェア工学2023 07 バージョン管理
ソフトウェア工学2023 07 バージョン管理ソフトウェア工学2023 07 バージョン管理
ソフトウェア工学2023 07 バージョン管理
 
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
Recap: Modern CI/CD with Tekton and Prow Automated via Jenkins X - Kubernetes...
 
Eclipse xtext 紹介
Eclipse xtext 紹介Eclipse xtext 紹介
Eclipse xtext 紹介
 
Ossで作成するチーム開発環境
Ossで作成するチーム開発環境Ossで作成するチーム開発環境
Ossで作成するチーム開発環境
 
CouchDB JP & BigCouch
CouchDB JP & BigCouchCouchDB JP & BigCouch
CouchDB JP & BigCouch
 
CMake multiplatform build-tool
CMake multiplatform build-toolCMake multiplatform build-tool
CMake multiplatform build-tool
 

More from Toru Tamaki

論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...
論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...
論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...Toru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes
論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes
論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex ScenesToru Tamaki
 
論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...
論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...
論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...Toru Tamaki
 
論文紹介:Tracking Anything with Decoupled Video Segmentation
論文紹介:Tracking Anything with Decoupled Video Segmentation論文紹介:Tracking Anything with Decoupled Video Segmentation
論文紹介:Tracking Anything with Decoupled Video SegmentationToru Tamaki
 
論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope
論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope
論文紹介:Real-Time Evaluation in Online Continual Learning: A New HopeToru Tamaki
 
論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...
論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...
論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...Toru Tamaki
 
論文紹介:Multitask Vision-Language Prompt Tuning
論文紹介:Multitask Vision-Language Prompt Tuning論文紹介:Multitask Vision-Language Prompt Tuning
論文紹介:Multitask Vision-Language Prompt TuningToru Tamaki
 
論文紹介:MovieCLIP: Visual Scene Recognition in Movies
論文紹介:MovieCLIP: Visual Scene Recognition in Movies論文紹介:MovieCLIP: Visual Scene Recognition in Movies
論文紹介:MovieCLIP: Visual Scene Recognition in MoviesToru Tamaki
 
論文紹介:Discovering Universal Geometry in Embeddings with ICA
論文紹介:Discovering Universal Geometry in Embeddings with ICA論文紹介:Discovering Universal Geometry in Embeddings with ICA
論文紹介:Discovering Universal Geometry in Embeddings with ICAToru Tamaki
 
論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement
論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement
論文紹介:Efficient Video Action Detection with Token Dropout and Context RefinementToru Tamaki
 
論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...
論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...
論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...Toru Tamaki
 
論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...
論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...
論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...Toru Tamaki
 
論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion
論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion
論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusionToru Tamaki
 
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous DrivingToru Tamaki
 
論文紹介:Spatio-Temporal Action Detection Under Large Motion
論文紹介:Spatio-Temporal Action Detection Under Large Motion論文紹介:Spatio-Temporal Action Detection Under Large Motion
論文紹介:Spatio-Temporal Action Detection Under Large MotionToru Tamaki
 
論文紹介:Vision Transformer Adapter for Dense Predictions
論文紹介:Vision Transformer Adapter for Dense Predictions論文紹介:Vision Transformer Adapter for Dense Predictions
論文紹介:Vision Transformer Adapter for Dense PredictionsToru Tamaki
 
動画像理解のための深層学習アプローチ Deep learning approaches to video understanding
動画像理解のための深層学習アプローチ Deep learning approaches to video understanding動画像理解のための深層学習アプローチ Deep learning approaches to video understanding
動画像理解のための深層学習アプローチ Deep learning approaches to video understandingToru Tamaki
 

More from Toru Tamaki (20)

論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...
論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...
論文紹介:Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Gene...
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes
論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes
論文紹介:MOSE: A New Dataset for Video Object Segmentation in Complex Scenes
 
論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...
論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...
論文紹介:MoLo: Motion-Augmented Long-Short Contrastive Learning for Few-Shot Acti...
 
論文紹介:Tracking Anything with Decoupled Video Segmentation
論文紹介:Tracking Anything with Decoupled Video Segmentation論文紹介:Tracking Anything with Decoupled Video Segmentation
論文紹介:Tracking Anything with Decoupled Video Segmentation
 
論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope
論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope
論文紹介:Real-Time Evaluation in Online Continual Learning: A New Hope
 
論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...
論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...
論文紹介:PointNet: Deep Learning on Point Sets for 3D Classification and Segmenta...
 
論文紹介:Multitask Vision-Language Prompt Tuning
論文紹介:Multitask Vision-Language Prompt Tuning論文紹介:Multitask Vision-Language Prompt Tuning
論文紹介:Multitask Vision-Language Prompt Tuning
 
論文紹介:MovieCLIP: Visual Scene Recognition in Movies
論文紹介:MovieCLIP: Visual Scene Recognition in Movies論文紹介:MovieCLIP: Visual Scene Recognition in Movies
論文紹介:MovieCLIP: Visual Scene Recognition in Movies
 
論文紹介:Discovering Universal Geometry in Embeddings with ICA
論文紹介:Discovering Universal Geometry in Embeddings with ICA論文紹介:Discovering Universal Geometry in Embeddings with ICA
論文紹介:Discovering Universal Geometry in Embeddings with ICA
 
論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement
論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement
論文紹介:Efficient Video Action Detection with Token Dropout and Context Refinement
 
論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...
論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...
論文紹介:Learning from Noisy Pseudo Labels for Semi-Supervised Temporal Action Lo...
 
論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...
論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...
論文紹介:MeMViT: Memory-Augmented Multiscale Vision Transformer for Efficient Lon...
 
論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion
論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion
論文紹介:Revealing the unseen: Benchmarking video action recognition under occlusion
 
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
 
論文紹介:Spatio-Temporal Action Detection Under Large Motion
論文紹介:Spatio-Temporal Action Detection Under Large Motion論文紹介:Spatio-Temporal Action Detection Under Large Motion
論文紹介:Spatio-Temporal Action Detection Under Large Motion
 
論文紹介:Vision Transformer Adapter for Dense Predictions
論文紹介:Vision Transformer Adapter for Dense Predictions論文紹介:Vision Transformer Adapter for Dense Predictions
論文紹介:Vision Transformer Adapter for Dense Predictions
 
動画像理解のための深層学習アプローチ Deep learning approaches to video understanding
動画像理解のための深層学習アプローチ Deep learning approaches to video understanding動画像理解のための深層学習アプローチ Deep learning approaches to video understanding
動画像理解のための深層学習アプローチ Deep learning approaches to video understanding
 

ソフトウェア工学2023 14 ビルド