C - スタティックライブラリとダイナミックライブラリ - ホットスワップ可能なコード - ビルド
Head First C ―頭とからだで覚えるCの基本、 David Griffiths(著)、 Dawn Griffiths(著)、 中田 秀基(監修)、 木下 哲也(翻訳)、 O’Reilly Media)の 8章(スタティックライブラリとダイナミックライブラリ - ホットスワップ可能なコード)、p.367(自分で考えてみよう)の解答を求めてみる。
Makefile
hfcal.o: hfcal.c
cc -c -I./includes hfcal.c -o hfcal.o
elliptical.o: elliptical.c hfcal.o
cc -c -I./includes elliptical.c -o elliptical.o
libhfcal.a: hfcal.o
ar -rcs ./libs/libhfcal.a hfcal.o
elliptical: elliptical.o libhfcal.a
cc elliptical.o -L./libs -lhfcal -o elliptical
入出力結果(Terminal, Zsh)
% make elliptical
cc -c -I./includes hfcal.c -o hfcal.o
cc -c -I./includes elliptical.c -o elliptical.o
ar -rcs ./libs/libhfcal.a hfcal.o
cc elliptical.o -L./libs -lhfcal -o elliptical
% ./elliptical
体重:115.20ポンド
距離:11.30マイル
カロリー:1028.39カロリー
%