日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

多个Makefile文件编译,Makefile多目标编译和多层次编译

發布時間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 多个Makefile文件编译,Makefile多目标编译和多层次编译 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

多個Makefile文件編譯,Makefile多目標編譯和多層次編譯

  • README
  • Makefile多目標編譯
  • Makefile多層次編譯
    • a文件夾
    • b文件夾
    • include文件夾
    • obj文件夾
  • 多個Makefile文件編譯
  • 相關截圖
    • make文件夾
    • a_b文件夾
    • project2文件夾

README

文件夾以及文件說明。
根文件夾為make,實現多個Makefile文件編譯。

Dir make----- /* 一級文件夾:多Makefile編譯 */| |-------a_b /* 二級文件夾:多目標編譯 */| || |-------obj /* 三級文件夾:a_b工程目標文件生成的指定位置 */| || |------------------main_a.c /* 第一個目標主文件 */| |------------------main_b.c /* 第二個目標主文件 */| |------------------test_a.c /* 第一個目標printf功能函數文件 */| |------------------test_b.c /* 第二個目標printf功能函數文件 */| |------------------test_a.h /* 第一個目標功能函數聲明頭文件 */| |------------------test_b.h /* 第二個目標功能函數聲明頭文件 */| |------------------Makefile /* 二級文件夾a_b多目標編譯的Makefile文件 */||-------projects /* 二級文件夾:多層次編譯 */| || |-------a /* 三級文件夾:a功能函數實現 */| | || | |----------a.c /* a()功能函數實現 */| | |----------a.h /* a()功能函數聲明頭文件 */| | | |-------b /* 三級文件夾: b功能函數實現 */| | || | |----------b.c /* b()功能函數實現 */| | |----------b.h /* b()功能函數聲明頭文件 */| | | |-------include /* 三級文件夾:相關常量宏定義頭文件 */| | | | | |----------code.h /* 相關常量宏定義頭文件 */| || |-------obj /* 三級文件夾:project2工程目標文件生成的指定位置 */| | | |-------c.c /* c()功能函數實現 */| |-------c.h /* c()功能函數聲明頭文件 */| |-------main.c /* project2工程實現主函數,調用a(),b(),c()函數接口 */| |-------Makefile /* project2工程實現多層次編譯的Makefile */| ||-------Makefile /* make文件夾實現多個Makefile文件編譯,即調用projects和a_b文件夾下Makefile編譯 */!!! 注意: 所有非 main*.c 文件只具有簡單的printf功能 所有含有 main*.c 文件只有簡單的函數接口調用功能

Makefile多目標編譯

在文件夾a_b中實現。
main_a.c: 第一個目標主文件

#include <stdio.h> #include <stdlib.h> #include <test_a.h>int main() {print_a();return 0;}

test_a.c:第一個目標printf功能函數文件

#include <test_a.h>void print_a() {printf( "This is test_a.c!\n" );}

test_a.h:第一個目標功能函數聲明頭文件

#ifndef _TEST_A_H #define _TEST_A_H#include <stdio.h> #include <stdlib.h>void print_a();#endif

main_b.c:第二個目標主文件

#include <stdio.h> #include <stdlib.h> #include <test_b.h>int main() {print_b();return 0;}

test_b.c:第二個目標printf功能函數文件

#include <test_b.h>void print_b() {printf( "This is test_b.c!\n" );}

test_b.h:第二個目標功能函數聲明頭文件

#ifndef _TEST_B_H #define _TEST_B_H#include <stdio.h> #include <stdlib.h>void print_b();#endif

Makefile:二級文件夾a_b多目標編譯的Makefile文件

CC = gcc CFLAGS = -lm -Wall -g#get the posotion of current directory ROOT = $(PWD) #get the posotion of current library INCLUDE = -I$(ROOT) APP = $(ROOT)/obj#all the out files of first target OBJS1 = main_a.o \test_a.o#all the out files of second target OBJS2 = main_b.o \test_b.o #first and second target TARGETS1 = $(APP)/main_a TARGETS2 = $(APP)/main_b #total tagets TARGETS = $(TARGETS1) TARGETS += $(TARGETS2) #include the path of library CFLAGS += $(INCLUDE)OBJS = $(OBJS1) OBJS += $(OBJS2)all:$(TARGETS)$(TARGETS1):$(OBJS1)$(CC) -o $(TARGETS1) $(OBJS1) $(CFLAGS)$(TARGETS2):$(OBJS2)$(CC) -o $(TARGETS2) $(OBJS2) $(CFLAGS)clean:-$(RM) $(OBJS) -$(RM) $(TARGETS)

Makefile多層次編譯

Makefile文件

ROOT = $(PWD)A = $(ROOT)/a B = $(ROOT)/b INCLUDE = $(ROOT)/include APP = $(ROOT)/objCFLAGS = -I$(A) CFLAGS += -I$(B) CFLAGS += -I$(ROOT) CFLAGS += -I$(INCLUDE)OBJS = main.o $(A)/a.o $(B)/b.o c.o TARGET = $(APP)/appall:$(TARGET)$(TARGET):$(OBJS)$(CC) -o $(TARGET) $(OBJS) $(CFLAGS)clean:-$(RM) $(OBJS)-$(RM) $(TARGET)

c.c:c()功能函數實現

#include <stdio.h> #include <stdlib.h> #include <c.h> #include <code.h>void c(){printf( "%d: This is c function!\n" , C );}

c.h:c()功能函數聲明頭文件

#include<stdio.h> void c();

main.c:project2工程實現主函數,調用a(),b(),c()函數接口

#include <stdio.h> #include "a.h" #include "b.h" #include "c.h"void main(){a();}

a文件夾

三級文件夾: a功能函數實現
a.c:a()功能函數實現

#include <stdio.h> #include <stdlib.h> #include "a.h" #include "b.h" #include "c.h" #include <code.h>void a(){c();b();printf( "%d: This is a function!\n" , A );printf( "Well done!\n" );}

a.h:a()功能函數聲明頭文件

void a();

b文件夾

三級文件夾: b功能函數實現
b.c:b()功能函數實現

#include <stdio.h> #include <stdlib.h> #include "b.h" #include <code.h>void b(){printf( "%d: This is b function!\n" , B );}

b.h:b()功能函數聲明頭文件

#include <stdio.h>void b();

include文件夾

code.h:相關常量宏定義頭文件

#include <stdio.h> #include <stdlib.h>#define A 1 #define B 2 #define C 3

obj文件夾

編譯前為空文件夾,編譯時為project2工程目標文件生成的指定位置

多個Makefile文件編譯

Makefile:位于根文件夾make中

ROOT = $(PWD) SUBDIR = $(ROOT)/a_b SUBDIR += $(ROOT)/project2define make_subdir @for i in $(SUBDIR); do \( cd $$i && make $1 ) \ done; endefALL: $(call make_subdir)clean:$(call make_subdir , clean)

相關截圖

make文件夾

a_b文件夾

project2文件夾


/project2/a 文件夾

/project2/b 文件夾

/project2/include 文件夾

/project2/obj 文件夾

總結

以上是生活随笔為你收集整理的多个Makefile文件编译,Makefile多目标编译和多层次编译的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。