c語言學習筆記二十二

2021-09-01 13:43:52 字數 1916 閱讀 8088

自動處理標頭檔案的依賴關係

all:test34

test34:test34.o test33.o test31.o

gcc$~ -o $@

test34.o:test34.c test29.h test30.h test32.h

test33.o:test33.c test32.h test29.h

test31.o:test31.c test30.h test29.h

clean:

-rm main *.o

.phony:clean

生成目標檔案和原始檔的依賴關係

gcc -m test34.c

yuezhenhua@ubuntu:/opt/sdk/tc/makefile$ gcc -m test34.c

test34.o: test34.c /usr/include/stdio.h /usr/include/features.h \

/usr/include/i386-linux-gnu/bits/predefs.h \

/usr/include/i386-linux-gnu/sys/cdefs.h \

/usr/include/i386-linux-gnu/bits/wordsize.h \

/usr/include/i386-linux-gnu/gnu/stubs.h \

/usr/include/i386-linux-gnu/gnu/stubs-32.h \

/usr/lib/gcc/i686-linux-gnu/4.4.6/include/stddef.h \

/usr/include/i386-linux-gnu/bits/types.h \

/usr/include/i386-linux-gnu/bits/typesizes.h /usr/include/libio.h \

/usr/include/_g_config.h /usr/include/wchar.h \

/usr/lib/gcc/i686-linux-gnu/4.4.6/include/stdarg.h \

/usr/include/i386-linux-gnu/bits/stdio_lim.h \

/usr/include/i386-linux-gnu/bits/sys_errlist.h test29.h test30.h \

test32.h

如果不需要輸出系統檔案的依賴關係

gcc -mm *.c

yuezhenhua@ubuntu:/opt/sdk/tc/makefile$ gcc -mm *.c

test31.o: test31.c test30.h test29.h

test33.o: test33.c test32.h test29.h

test34.o: test34.c test29.h test30.h test32.h

把這些規則包含到makefile中

all: test34

test34: test34.o test33.o test31.o

gcc $^ -o $@

clean:

-rm test34 *.o

.phony: clean

sources = test34.c test33.c test31.c

include $(sources:.c=.d)

%.d: %.c

set -e; rm -f $@;

$(cc) -mm $(cppflags) $< > $@.$$$$;

sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;

rm -f $@.$$$$

常用的make命令列選項

-n 列印要執行的命令

-c可以切換到另一目錄執行該目錄下的makefile

-g 可以在命令列定義cflags變數

c語言學習筆記二十二

自動處理標頭檔案的依賴關係 all test34 test34 test34.o test33.o test31.o gcc o test34.o test34.c test29.h test30.h test32.h test33.o test33.c test32.h test29.h test...

c語言學習筆記二十

makefile基礎 基本規則 一般的程式都是由多個原始檔編譯鏈結而成,而這些原始檔的處理通常是由makefile來處 理示例 如下 test29.h ifndef main h define main h 宣告點型別 typedef struct point item t 宣告最大列和行變數 de...

二十二 Oracle學習筆記 Oracle異常

一 oralce異常 1.oracle低層定義了很多異常,每個異常都有乙個唯一的編碼,這些異常之中,有一些是比較常見的,oracle 給這些異常定義了名稱,可以直接使用,其他沒有名稱只有編碼的不能直接使用。2.異常的分類 1 預定義異常 既有編碼又有名稱的異常是預定義異常,此類異常可以直接使用 2 ...