makefile的簡單使用

2021-10-16 13:21:31 字數 1335 閱讀 9688

/*********************main.c**************/

#include "test1.h"

#include "test2.h"

#include int main()

/**********************test1.c***********************/

#include "test1.h"

#include void test1_func(char *str)

/*************************test1.h*******************/

#ifndef _test1_h

#define _test1_h

void test1_func(char *str);

#endif

/**********************test2.c**********************/

#include "test2.h"

#include void test2_func(char *str)

/**********************test2.h*********************/

#ifndef _test2_h

#define _test2_h

void test2_func(char *str);

#endif

首先兩個命令:gcc -c ***.c ***.h 的意思是在***.c中包含標頭檔案***.h,編譯器gcc依賴***.h編譯生成可執行檔案.o

gcc -o main main.o test1.o test.o   將由test1.c,test2.c,main.c生成的可執行檔案鏈結起來生成目標檔案main.lib,然後執行:./main可執行生成檔案。

#makefile

main:main.o test1.o test2.o #[目標檔案]:[依賴關係表] 鏈結

gcc -o main main.o test1.o test2.o

main.o:main.c test1.h test2.h #[需編譯檔案]:[依賴檔案] 編譯

gcc -c main.c

test1.o:test1.c test1.h

gcc -c test1.c

test2.o:test2.c test2.h

gcc -c test2.c

.phony:clean

clean:

rm -f *.o main

Makefile的簡單使用

簡介 乙個工程中的原始檔不計其數,其按型別 功能 模組分別放在若干個目錄中,makefile定義了一系列的規則來指定,哪些 檔案需要先編譯,哪些檔案需要後編譯,哪些檔案需要重新編譯,甚至於進行更複雜的功能操作,因為 makefile就像乙個shell 指令碼一樣,其中也可以執行作業系統的命令。lin...

makefile的簡單使用

乙個工程中的原始檔不計其數,其按型別 功能 模組分別放在若干個目錄中,makefile定義了一系列的規則來指定,哪些檔案需要先編譯,哪些檔案需要後編譯,哪些檔案需要重新編譯,甚至於進行更複雜的功能操作,因為 makefile就像乙個shell指令碼一樣,其中也可以執行作業系統的命令。linux 環境...

makefile的簡單使用

簡單說下makefile的使用,複雜的還沒有寫過,遇見再學習,隨時更新。用makefile的目的是為了管理大一點的專案,例如qt中的qmake等等 main main.o gcc main.o o main main.o main.c gcc c main.c clean rm f o this i...