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'.