Linux Makefile: Compile Four Files Simultaneously
This Makefile will compile four files (file1.c, file2.c, file3.c, file4.c) and create a program from them. The 'all' target is set as the default target and it depends on the 'program' target. The 'program' target depends on the four object files and will be compiled with the gcc command. The four object files will be created using the gcc -c command. The 'clean' target will remove all object files and the program.
.PHONY: all
all: program
program: file1.o file2.o file3.o file4.o gcc -o program file1.o file2.o file3.o file4.o
file1.o: file1.c gcc -c file1.c
file2.o: file2.c gcc -c file2.c
file3.o: file3.c gcc -c file3.c
file4.o: file4.c gcc -c file4.c
clean: rm -f *.o program
原文地址: https://www.cveoy.top/t/topic/nwGW 著作权归作者所有。请勿转载和采集!