linux下自己写个软件

一、首先是建立三个文件 test_1.c test_2.c test_3.c
test_1.c
    #include <stdio.h>
    #include <stdlib.h>
    int main(){
        printf("Holle World 1111111111 \n");
        linkme2();
    }

test_2.c

    #include <stdio.h>
    #include <stdlib.h>
        int linkme2(void){
        printf("Holle World 222222222222222\n");
        linkme3();
    }

test_3.c
    #include <stdio.h>
    #include <stdlib.h>
        int linkme3(void){
        printf("Holle World 333333333333\n");
    }

二、进行编译  
    gcc -o test test_1.c test_2.c test_3.c

三、直接运行,可以直接看到效果
    ./test

makefile 的制作方法:

    1、了解makefile的语法
        建立makefile,并且加入一下的内容
              main:test_1.o test_2.o test_3.o
              <tab>gcc -o test test_1.o test_2.o test_3.o
              clean:
              <tab>rm -rf test_1.o test_2.o test_3.o
   2、make #注意这里   make其实是gun下的一个工具,在加入了之后会自动的将.c的文件进行gcc的操作,具体的效果如下:
    cc    -c -o test_1.o test_1.c
    cc    -c -o test_2.o test_2.c
    cc    -c -o test_3.o test_3.c
    gcc -o test test_1.o test_2.o test_3.o
    3、make clean #将生成的编译文件给自动的删除掉
        rm -rf test_1.o test_2.o test_3.o

    4、make clean test   #进行检测 源码是否有变化
        rm -rf test_1.o test_2.o test_3.o
        make: Nothing to be done for `test'.
 

猜你喜欢

转载自my.oschina.net/u/1780456/blog/1522945
今日推荐