Makefile 示例
这是用于编译 hello 程序的 Makefile 示例。该程序由三个文件
main.cpp、
factorial.cpp和
hello.cpp组成。
# Define required macros here
SHELL = /bin/sh
OBJS = main.o factorial.o hello.o
CFLAG =-Wall-g
CC = gcc
INCLUDE =
LIBS =-lm
hello:${OBJ}
${CC} ${CFLAGS} ${INCLUDES}-o $@ ${OBJS} ${LIBS}
clean:
-rm-f *.o core *.core
.cpp.o:
${CC} ${CFLAGS} ${INCLUDES}-c
# Define required macros here
SHELL = /bin/sh
OBJS = main.o factorial.o hello.o
CFLAG =-Wall-g
CC = gcc
INCLUDE =
LIBS =-lm
hello:${OBJ}
${CC} ${CFLAGS} ${INCLUDES}-o $@ ${OBJS} ${LIBS}
clean:
-rm-f *.o core *.core
.cpp.o:
${CC} ${CFLAGS} ${INCLUDES}-c $<
lt;
现在您可以使用
make 构建您的程序
hello。如果您将发出命令
make clean,那么它会删除当前目录中可用的所有目标文件和核心文件。