makefile入门

来源:互联网 发布:大数据修炼系统txt 编辑:程序博客网 时间:2024/06/07 05:31

                  linux下编程,makefile的重要性不用多说,网上一大堆,今天简单的实战一下。

[xxx@localhost test]$ lsmakefile  test1.cpp  test2.cpp[xxx@localhost test]$ cat test1.cpp #include<stdio.h>int main(){   printf("this is test1\n");   return 0;}[xxx@localhost test]$ cat test2.cpp #include<stdio.h>int main(){   printf("this is test2\n");   return 0;}[xxx@localhost test]$ cat makefile all:test1 test2test1:test1.o g++ test1.o -o test1test2:test2.og++ test2.o -o test2test1.o:test1.cppg++ -c test1.cpp -o test1.otest2.o:test2.cppg++ -c test2.cpp -o test2.oclean:rm -fr *.o [xxx@localhost test]$ 

执行:

[xxx@localhost test]$ makeg++ -c test1.cpp -o test1.og++ test1.o -o test1g++ -c test2.cpp -o test2.og++ test2.o -o test2[xxx@localhost test]$ lsmakefile  test1  test1.cpp  test1.o  test2  test2.cpp  test2.o[xxx@localhost test]$ ./test1this is test1[mapan@localhost test]$ ./test2this is test2[xxx@localhost test]$ 
all作用:makefile会把第一个目标作为默认,all可以指定多个目标

test.o:test.cpp这表示依赖关系,标明生成test.o需要test.cpp

[mapan@localhost test]$ make clean rm -fr *.o 
make clean清除所有.o文件



原创粉丝点击