ls -l 查看文件详细信息

1.gcc -E test.c -o test.i
//预编译
gedit test.i //查看:高级C

2.gcc -Wall -S test.i -o test.s
//编译显示所有警告
gedit test.s //查看:介于C与汇编之间的

3. as test.s -o test.o
nano test.o//强行打开是乱码

一步到位:gcc -c test.c
gcc test.o
./a.out

five.c,five.h//新建
gcc -o test test.c five.c //编译为test

gedit Makefile
内容:
test: test.c five.c
gcc -o test.c five.c
clean:rm test

make clean
ls
make
ls
./test

修改其中一个文件,修改Makefile如下,改善编译
test: test.o five.o #源文件
TAB gcc -o test.o five.o #命令
test.o: test.c #源文件
TAB gcc -c test.c #命令
five.o: five.c #源文件
TAB gcc -c five.c #命令
clean:rm test #删除test
TAB rm *.o #删除所有.o

make clean

再次修改其中一个文件,修改Makefile如下,改善编译
方便以后修改调整程序
CC=gcc #像宏定义
CFLAGS=-c -Wall #像宏定义
#使用替换 $(。。。)
all:test
test: test.o five.o #源文件
TAB $(CC) -o test.o five.o #命令
test.o: test.c #源文件
TAB $(CC) $(CFLAGS) test.c #命令
five.o: five.c #源文件
TAB $(CC) $(CFLAGS) five.o #命令
clean:rm test #删除test
TAB rm *.o #删除所有.o

一个简单的makefile示例及其注释
  相信在unix下编程的没有不知道makefile的,刚开始学习unix平台
下的东西,了解了下makefile的制作,觉得有点东西可以记录下。
  下面是一个极其简单的例子:
现在我要编译一个Hello world,需要如下三个文件:
  1. print.h
      #include<stdio.h>
      void printhello();

  2. print.c
      #include"print.h"
      void printhello(){
        printf("Hello, world\n");
      }

   3. main.c
      #include "print.h"
      int main(void){
        printhello();
        return 0;
      }

  好了,很简单的程序了。如果我们想要编译成功需要哪些步骤呢?
我认为在这里需要理解的就两步:
  # 为每一个 *.c文件生成 *o文件。
  # 连接每一个*o文件,生成可执行文件。
下面的makefile 就是根据这样的原则来写的。

一:makefile 雏形:

#makefile的撰写是基于规则的,当然这个规则也是很简单的,就是:
#target : prerequisites
  command  //任意的shell 命令

实例如下:
makefile:
    helloworld : main.o print.o #helloword 就是我们要生成的目标
                 # main.o print.o是生成此目标的先决条件
      gcc -o helloworld main.o print.o#shell命令,最前面的一定是一个tab键

    mian.o : mian.c print.h
      gcc -c main.c
    print.o : print.c print.h
      gcc -c print.c
    
    clean :          
        rm helloworld main.o print.o
  OK,一个简单的makefile制作完毕,现成我们输入 make,自动调用Gcc编译了,
输入 make clean就会删除 hellowworld mian.o print.o

二:小步改进:

  在上面的例子中我们可以发现 main.o print.o 被定义了多处,
我们是不是可以向C语言中定义一个宏一样定义它呢?当然可以:
makefile:
    objects = main.o print.o #应该叫变量的声明更合适

    helloworld : $(objects) //声明了变量以后使用就要$()了
      gcc -o helloworld$(objects)
    mian.o : mian.c print.h
      gcc -c main.c
    print.o : print.c print.h
      gcc -c print.c
    
    clean :          
        rm helloworld $(objects)
修改完毕,这样使用了变量的话在很多文件的工程中就能体现出方便性了。

三:再进一步:

  再看一下,为没一个*.o文件都写一句gcc -c main.c是不是显得多余了,
能不能把它干掉?而且 main.c 和print.c都需要print.h,为每一个都写上是
不是多余了,能不能再改进?
能,当然能了:
makefile:
    objects = main.o print.o

    helloworld : $(objects)
      gcc -o helloworld$(objects)
    
    $(objects) : print.h # 都依赖print.h
    mian.o : mian.c #干掉了gcc -c main.c 让Gun make自动推导了。
    print.o : print.c  
  
    clean :          
        rm helloworld $(objects)

好了,一个简单的makefile就这样完毕了,简单吧。

Makefile学习笔记的更多相关文章

  1. [转]Windows平台下Makefile学习笔记

    Windows平台下Makefile学习笔记(一) 作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译 ...

  2. <转>Windows平台下Makefile学习笔记(二)

    本文转自:http://blog.csdn.net/clever101/article/details/8286066 上次我们学习了怎么用Makefile编译一个控制台工程.这次我们学习一下如何使用 ...

  3. makefile学习笔记(多目录嵌套调用、变量使用)

    http://blog.csdn.net/leexiang_han/article/details/9274229   学习了几天的makefile的嵌套调用编写也有一些心得,先声明,我也是初学者写文 ...

  4. makefile学习笔记(一)

    1.1:make概述 在linux环境下使用make工具能够比较容易的构建一个属于自己的工程,整个工程的编译只需要一个命令就可以完成编译.连接以至于最后的执行.不过我们需要投入一些时间去学习如何完成m ...

  5. <转>Windows平台下Makefile学习笔记(一)

    本文转自:http://blog.csdn.net/clever101/article/details/8147352 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译平台的问题(发 ...

  6. 【VS开发】Windows平台下Makefile学习笔记

    作者:朱金灿 来源:http://blog.csdn.net/clever101 决心学习Makefile,一方面是为了解决编译开源代码时需要跨编译平台的问题(发现一些开源代码已经在使用VS2010开 ...

  7. makefile 学习笔记

    1/ 编写简单makefile test_out: test.o g++ test.o -o test_out test.o: test.cpp test.h g++ -c test.cpp test ...

  8. Linux下Makefile学习笔记

    makefile 可以用于编译和执行多个C/C++源文件和头文件. (1) #include "file.h" 和 #include <file.h> 的区别 #inc ...

  9. Makefile的学习笔记

    Makefile的学习笔记 标签: makefilewildcard扩展includeshellfile 2012-01-03 00:07 9586人阅读 评论(2) 收藏 举报  分类: Linux ...

随机推荐

  1. Compound Interest Calculator4.0

    Compound Interest Calculator4.0 1.团队协作准备:每个同学在github上完成FORK,COMMENT(学号后三位+姓名),PR,MERGE的过程. 2.你的RP由你的 ...

  2. --专访雷果国: 从1.5K到18K 一个程序员的5年成长之路--

    导语:今年三月份,在CSDN博客和新浪微博上有一篇<从1.5K到18K,一个程序员的5年成长之路>被众人分享和传阅,这篇博文首先介绍了作者自学之初薄弱的基础,然后通过流水账形式分享了那个从 ...

  3. 笔记9:winfrom的一些知识点(二)

    一.新建,和删除文件夹 private void button4_Click(object sender, EventArgs e) { Directory.Delete(@"F:\&quo ...

  4. hdu----(1671)Phone List(Trie带标签)

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. NSInternalInconsistencyException: loaded the "XXXView" nib but the view outlet was not set

    运行过程中App崩溃,报错如标题. 原因: viewController的view没有绑定xib的view. 解决方法: 在File's Owner中将view与viewController的view ...

  6. iOS开发 iOS10推送必看

    iOS10更新之后,推送也是做了一些小小的修改,下面我就给大家仔细说说.希望看完我的这篇文章,对大家有所帮助. 一.简单入门篇---看完就可以简单适配完了 相对简单的推送证书以及环境的问题,我就不在这 ...

  7. IntelliJ IDEA 中properties中文显示问题

  8. Javascript 中的false、0、null、undefined和空字符串对象

    在Javascript中,我们经常会接触到题目中提到的这5个比较特别的对象——false.0.空字符串.null和undefined.这几个对象很容易用错,因此在使用时必须得小心. 类型检测 我们下来 ...

  9. html标签marquee实现走马灯效果(文字浮动)

    marquee标签实现文字或图片的移动效果 <marquee direction = "right">文字<marquee>

  10. 动态加载的数据,hover效果

    $('.option li').live('mouseenter',function(){            $(this).addClass("active");       ...