Skip to content

Instantly share code, notes, and snippets.

@holys
Last active December 11, 2015 00:39
Show Gist options
  • Select an option

  • Save holys/4518153 to your computer and use it in GitHub Desktop.

Select an option

Save holys/4518153 to your computer and use it in GitHub Desktop.
简单版makefile
#include <math.h>
double compute(double x, double y) {
return pow(x, y);
}
powe: power.o compute.o
gcc power.o compute.o -lm -o powe
power.o: power.c
gcc -c power.c
compute.o: compute.c
gcc -c compute.c
#include <stdio.h>
double compute(double x, double y);
int main() {
float x, y;
printf("The program takes x and y from stdin and displays x^y.\n");
printf("Enter integer x: ");
scanf("%f", &x);
printf("Enter integer y: ");
scanf("%f", &y);
printf("x^y is: %6.0f\n", compute(x, y));
return 0;
}
@holys
Copy link
Author

holys commented Jan 12, 2013

然后执行make.
执行过程:

5:43 david@debian /home/david
% make
gcc -c power.c
gcc -c compute.c
gcc power.o compute.o -lm -o powe

注意:makefile里面的 -lmcompute.c用到了/usr/lib/libm.so的缘故.

@holys
Copy link
Author

holys commented Jan 14, 2013

Make rules
target-list: dependency-list
<Tab>command-list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment