【0】README
编译文件(nasm + gcc),特别是编译目标文件的依赖文件;本文旨在回顾 gcc 和 nams 编译器的编译命令,以及如果有多个依赖文件该如何编译;
【1】编译文件
1.1)编译 lib/syscall.asm(lib/syscall.asm)
nasm -I include/sys/ lib/syscall.asm -o syscall.o
1.2)编译 lib/string.asm(lib/string.asm)
nasm -I include/sys/ lib/string.asm -o string.o
1.3)编译 fs 的接口(lib/open.c + lib/read.c + lib/write.c + lib/close.c + lib/unlink.c)
[hadoop@hadoop0 c]$ gcc -M lib/open.c -I include/ -I include/sys (查找 lib/open.c 所依赖的文件)
open.o: lib/open.c include/type.h include/stdio.h include/type.h
include/sys/const.h include/sys/protect.h include/string.h
include/sys/fs.h include/sys/proc.h include/sys/tty.h
include/sys/console.h include/sys/global.h include/sys/proto.h
gcc -I include/ -I include/sys -c -fno-builtin lib/unlink.c -o lib/unlink.o
1.4)编译MM 的 接口(lib/fork.c + lib/exit.c + lib/wait.c)
[hadoop@hadoop0 c]$ gcc -I include/ -I include/sys/ -c -fno-builtin lib/fork.c -o lib/fork.o
[hadoop@hadoop0 c]$ gcc -I include/ -I include/sys/ -c -fno-builtin lib/exit.c -o lib/exit.o
[hadoop@hadoop0 c]$ gcc -I include/ -I include/sys/ -c -fno-builtin lib/wait.c -o lib/wait.o
1.5)编译SYS 的接口(lib/getpid.c)
gcc -I include/ -I include/sys/ -c -fno-builtin lib/getpid.c -o lib/getpid.o
1.6)others (lib/misc.c + lib/vsprinf.c + lib/printf.c)
[hadoop@hadoop0 c]$ gcc -I include/ -I include/sys/ -c -fno-builtin lib/misc.c -o lib/misc.o
[hadoop@hadoop0 c]$ gcc -I include/ -I include/sys/ -c -fno-builtin lib/vsprintf.c -o lib/vsprintf.o
[hadoop@hadoop0 c]$ gcc -I include/ -I include/sys/ -c -fno-builtin lib/printf.c -o lib/printf.o
1.7)将上述目标文件编译为 C运行时库
[hadoop@hadoop0 c]$ ar rcs lib/orangescrt.a lib/syscall.o lib/printf.o lib/vsprintf.o
> lib/string.o lib/misc.o lib/open.o lib/read.o lib/write.o lib/close.o
> lib/unlink.o lib/getpid.o lib/fork.o lib/exit.o lib/wait.o
版权声明:本文为博主原创文章,未经博主允许不得转载。