zoukankan      html  css  js  c++  java
  • LinuxC编程怎么MakeFile

      在linux下我们都知道可以利用命令gcc hello.c -o hello 命令来变异c语言程序。其中gcc hello.c -o hello中 hello是给这个编译后生成的可执行文件取个别名 再利用./hello命令运行c程序。

    可是如果c程序比较多呢?每个都这样编译太麻烦了,聪明的程序员想出了一个很好的工具,那就是make,利用make来实现同时编译。

    首先,假设有3个文件

    1.greeting.h

    其中内容是

    #ifndef _GREETING_H

    #define _GREETING_H

    void greeting(char *a);

    #endif

    2.greeting.c  //具体实现greeting.h的函数

    #include<stdio.h>
    
    #include"greeting.h"
    
    void greeting(char *a)
    
    {
    
      printf("Hello %s
    ",a);
    
    }
    

      

    3.test.c //主程序,用来调用greeting(char *a)函数的

    #include<stdio.h>
    
    #include"greeting.h"
    
    int main()
    
    {
    
      char a[20] = "zzl oyxt";
    
      greeting(a);
    
    }
    
     
    

      

    接下来就是来写我们的Makefile了

    vi Makefile进行文件编辑

    test : greeting.o test.o
    
      gcc greeting.o test.o -o test
    
    greeting.o: greeting.h greeting.c
    
      gcc -c greeting.c
    
    test.o:test.c greeting.h
    
      gcc -c test.c
    

      

    编辑完成保存之后,输入make命令,会生成一个可执行文件 test

    那么执行./test就可以执行了。

  • 相关阅读:
    前端笔记-jquery
    git的使用
    前端笔记-bom
    微信小程序没找到构建npm或者没找到node_modules目录
    微信小程序判断 wx:if wx:else
    微信小程序提示云函数部署不成功
    cmd如何进入文件夹
    微信小程序view居中
    vue页面跳转兄弟组件传值
    vue全局变量apiurl
  • 原文地址:https://www.cnblogs.com/zzlback/p/8962662.html
Copyright © 2011-2022 走看看