jasmine214--love

          只有當你的內心總是充滿快樂、美好的愿望和寧靜時,你才能擁有強壯的體魄和明朗、快樂或者寧靜的面容。
          posts - 731, comments - 60, trackbacks - 0, articles - 0

          簡單帶子目錄的makefile練習

          Posted on 2012-01-10 21:18 幻海藍夢 閱讀(1693) 評論(1)  編輯  收藏 所屬分類: Linux配置管理Shell
            開始學linux。我練習寫的第一個帶子目錄的makefile文件。
            1。建立文件夾 wulong
            wulong中含 三個文件夾 include source pro 和makefile文件。
            include 中包含 hai.h頭文件。
            source 中包含 hello.c文件。
            pro 中包含 haia.c haib.c文件。
            
            makefile文件內容有兩種寫法:
            makefile 第一種寫法:
            //*********************
            CC=gcc #選擇編譯器類型為gcc
            VPATH= include : pr : source #列明文件存放目錄
            
            hello: hello.o haia.o haib.o
             $(CC) -o hello hello.o haia.o haib.o
            hello.o:hello.c hai.h
             $(CC) -c hello.c
            haia.o: haia.c hai.h
             $(CC) -c haia.c
            haib.o: haib.c hai.h
             $(CC) -c haib.c
            .PHONY: clean
            clean:
             rm hello $(obj)
            //*************************
            
            
            
            makefile第二種寫法(簡化版):
            //********************************
            CC=gcc #選擇編譯種類
            
            VPATH= include : pr : source #在include pr source 三目錄下查找文件
            
            obj= hello.o haia.o haib.o #
            
            hello:$(obj) #
             $(CC) -o hello $(obj)
            
            $(obj): hai.h
            
            .PHONY: clean
            clean:
             rm hello $(obj)
            //**********************************
            
            
            hai.h文件內容為:
            //************************
            #include "stdio.h"
            extern void haiprinta();
            extern void haiprintb();
            //****************
            
            hello.c內容為:
            //****************
            #include "../include/hai.h"
            
            int main(void)
            {
            haiprinta();
            haiprintb();
            return 0;
            }
            //**************
            
            haia.c內容為:
            //************
            #include "../include/hai.h"
            
            void haiprinta()
            {
            printf("hai aaaaaaaaaa\n");
            }
            //**************
            
            
            haib.c內容為:
            //**************
            #include "../include/hai.h"
            
            void haiprintb()
            {
            printf("haib bbbbbbbbbbbbbb\n");
            }
            //*******************
            
            2。make 調用makefile生成 可執行文件 hello
            
            3. 運行 hello顯示打印結果:
            [HAI@localhost wulong]$ ./hello
            hai aaaaaaaaaa
            haib bbbbbbbbbbbbbb
            [HAI@localhost wulong]$
            
            到此結束,恭喜!

          原文:
          http://blog.tianya.cn/blogger/post_show.asp?BlogID=2058037&PostID=17326631

          Feedback

          # re: 簡單帶子目錄的makefile練習[未登錄]  回復  更多評論   

          2014-06-24 14:11 by elaine
          您好,我想單獨請教一下visualsvn server與subversion的區別,既然visualsvn server集成了subversion,為什么還有那么多的人在用subversion?
          主站蜘蛛池模板: 白水县| 濮阳市| 海安县| 枝江市| 罗定市| 门源| 景德镇市| 昌平区| 五原县| 宜丰县| 虹口区| 定州市| 伊金霍洛旗| 丰镇市| 哈巴河县| 安图县| 固安县| 舟曲县| 巧家县| 松滋市| 安溪县| 疏勒县| 建始县| 开原市| 宁陕县| 陆良县| 广德县| 乃东县| 芜湖市| 泸西县| 定远县| 河源市| 乌苏市| 永春县| 桂东县| 连平县| 文昌市| 南部县| 镇巴县| 板桥市| 阿荣旗|