C - スタティックライブラリとダイナミックライブラリ - ホットスワップ可能なコード - ディレクトリ構成, sharedオプション
Head First C ―頭とからだで覚えるCの基本、 David Griffiths(著)、 Dawn Griffiths(著)、 中田 秀基(監修)、 木下 哲也(翻訳)、 O’Reilly Media)の 8章(スタティックライブラリとダイナミックライブラリ - ホットスワップ可能なコード)、p.378(長いエクササイズ)の解答を求めてみる。
Makefile
hfcal.o: hfcal_uk.c
cc -c -I./includes hfcal_uk.c -o hfcal.o
libhfcal.dylib: hfcal.o
cc -shared hfcal.o -o ./libs/libhfcal.dylib
elliptical.o: elliptical.c hfcal.o
cc -c -I./includes elliptical.c -o elliptical.o
elliptical: elliptical.o libhfcal.dylib
cc elliptical.o -L./libs -lhfcal -o elliptical
入出力結果(Terminal, Zsh)
% make elliptical
cc -c -I./includes hfcal_uk.c -o hfcal.o
cc -c -I./includes elliptical.c -o elliptical.o
cc -shared hfcal.o -o ./libs/libhfcal.dylib
cc elliptical.o -L./libs -lhfcal -o elliptical
% ./elliptical
体重:52.25 kg
距離:18.19 km
カロリー:1028.39カロリー
%