專案架構:
其中各個檔案的內容請自己填寫。
專案被劃分為不同的多個模組:
第一階段:將每個模組中的**編譯稱為靜態庫檔案(compile)
第二階段:將每個模組的靜態庫檔案最終鏈結成最終的可執行程式(link)
模組的編譯:makefile
.phony : all注意:實驗過程中需要自己建立build及各模組的資料夾,並將makefile中的絕對路徑改為自己**的路徑。dir_build := /root/w_share/dt/tobemaster/makefile/20/build
dir_common_inc := /root/w_share/dt/tobemaster/makefile/20/common/inc
dir_src :=src
dir_inc :=inc
type_inc :=.h
type_src :=.c
type_obj :=.o
type_dep :=.dep
ar :=ar
arflags :=crs
cc :=gcc
cflags := -i$(dir_inc) -i$(dir_common_inc)
ifeq ($(debug),
true
)cflags += -g
endif
module :=$(realpath .)
module :=$(notdir $(module))
dir_output := $(addprefix $(dir_build)/, $(module))
output :=$(module).a
output := $(addprefix $(dir_build)/, $(output))
srcs := $(wildcard $(dir_src)/*
$(type_src))
objs := $(srcs:$(type_src)=$(type_obj))
objs := $(patsubst $(dir_src)/%, $(dir_output)/%, $(objs))
deps := $(srcs:$(type_src)=$(type_dep))
deps := $(patsubst $(dir_src)/%, $(dir_output)/%, $(deps))
vpath %$(type_inc) $(dir_inc)
vpath %$(type_inc) $(dir_common_inc)
vpath %$(type_src) $(dir_src)
-include $(deps)
all : $(output)
@echo "success! target ==> $(output)"
$(output) : $(objs)
$(ar) $(arflags) $@ $^
$(dir_output)/%$(type_obj) : %$(type_src)
$(cc) $(cflags) -o $@ -c $(filter %$(type_src), $^)
$(dir_output)/%$(type_dep) : %$(type_src)
@echo "creating $@ ..."
@set -e; \
$(cc) $(cflags) -mm -e $(filter %$(type_src), $^) | sed 's,\(.*\)\.o[ :]*,$(dir_output)/\1$(type_obj) $@ : ,g' > $@
輸出結果:
這裡我們看到在build/common下成功生成了依賴檔案和編譯後的檔案,並將這些.o檔案打包後放入build資料夾下。
思考:如何編寫專案makefile使其能夠觸發模組makefile的呼叫,並最終生成可執行程式?
第44課 函式引數的秘密(上)
1 函式引數在本質上與區域性變數相同,都在棧上分配空間 2 函式引數的初始值是函式呼叫時的實參值 3 c標準只規定了 必須要將每個實參的具體值求出來之後才能進行函式呼叫,並沒有規定函式引數的求值順序,求值順序依賴於編譯器的實現 比如void func 引數表示式1,引數表示式2,引數表示式3 這三個...
第 2 8 課 JSON 編譯碼的使用
在實際開發中,經常使用到資料交換格式,如 json 或 xml。flutter 裡也同樣可以處理 json 格式的解析 編碼操作,我們可以實現將乙個 json 字串轉為實體類或將乙個實體物件轉為json 格式字串。本節課主要講解 flutter 裡的 json 編譯碼的具體用法,並結合案例進行詳細的...
第20課 初始化列表的使用
類中是否可以定義const成員?下面的類定義是否合法?如果合法,ci 的值是什麼,儲存在 1 class test 27 1 include 2 3class test412 intgetci 1316 17 1819 intmain 20類中的const成員 在c中 const 修飾的變數必須在定...