makefile 编写

s11511@~/EXCERSICE/testone>$cat compute.c
#include "mymath.h"
#include <stdio.h>
int main() {
        int num;
        printf("Input a number:");
        scanf("%d",&num);
        printf("The power of %d is %d\n",num,square(num));
        return 0;
}
s11511@~/EXCERSICE/testone>$cat mymath.c
int square(int num){
        return num*num;
}
s11511@~/EXCERSICE/testone>$cat makefile
CC=gcc
TARGET=compute
DEPEND=compute.o  mymath.o
$(TARGET):$(DEPEND)
        $(CC) -o $@ $^  -g -Wall
.c.o:
        $(CC) -c $^  -g
.PHONY:clean
clean:
        rm $(DEPEND)

s11511@~/EXCERSICE/testone>$cat mymath.h

int square(int num);


你可能感兴趣的:(makefile)