• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 51, 文章 - 1, 評論 - 41, 引用 - 0
            數據加載中……

            帶依賴關系的makefile簡易例子

            # makefile 開始

            # 編譯相關的選項
            CC = g++
            CPPFLAG =

            # 所有的cpp源文件或者手動添加文件
            SOURCES = $(wildcard *.cpp)
            #SOURCES = main.cpp \
            #          test_func.cpp    \
            #          test_class.cpp

            # 與源文件對應的目標文件和依賴文件
            OBJECTS = $(SOURCES:.cpp=.o)
            DEPENDS = $(SOURCES:.cpp=.d)

            # 第一個編譯模板
            all: test.exe


            # 添加依賴文件
            sinclude $(DEPENDS)


            test.exe: $(OBJECTS)
                $(CC) $(OBJECTS) -o test.exe


            $(OBJECTS): %.o: %.cpp
                $(CC) -c $(CPPFLAG) $< -o $@


            # 生成依賴文件,由于依賴文件也依賴源文件,因此需要增加xxx.d,如:
            # main.o: main.cpp test_func.hpp test_class.hpp
            # main.d main.o: main.cpp test_func.hpp test_class.hpp
            # 一般的例子會使用sed實現這個功能,在這里我編寫了print.exe實現該功能。
            %.d: %.cpp print.exe
                print.exe $@ > $@
                $(CC) -MM $< >> $@

             

            # 輔助生成依賴文件的程序
            print.exe: print.c
                $(CC) print.c -o print.exe

             

            #清除所有文件
            clean:
                del test.exe print.exe $(OBJECTS) $(DEPENDS)

             

            #makefile 結束

             

            // print.c 開始

            #include <cstdio>
            int main(int argc, const char* argv[]) {
                if (argc > 1) {
                    printf("%s ", argv[1]);
                }
                return 0;
            }

            // print.c 結束

             

            // main.cpp 開始

            #include "test_func.hpp"
            #include "test_class.hpp"

            int main() {
                TestClass::Print();
                Print();
            }

            // main.cpp 結束

             

            // test_class.hpp 開始

            #ifndef TEST_CLASS_HPP
            #define TEST_CLASS_HPP
            class TestClass {
            public:
                static void Print();
            };

            #endif // TEST_CLASS_HPP

            // test_class.hpp 結束

             

            // test_class.cpp 開始

            #include <cstdio>
            #include "test_class.hpp"

            void TestClass::Print() {
                printf("TestClass\n");
            }

            // test_class.cpp 結束

             

            // test_func.hpp 開始

            #ifndef TEST_FUNC_HPP
            #define TEST_FUNC_HPP

            void Print();

            #endif // TEST_FUNC_HPP

            // test_func.hpp 結束

             

            // test_func.cpp 開始

            #include <cstdio>
            #include "test_func.hpp"

            void Print() {
                printf("TestFunc\n");
            }

            // test_func.cpp 結束

            posted on 2014-05-14 22:34 lemene 閱讀(713) 評論(0)  編輯 收藏 引用

            国产午夜久久影院| 久久久久久久久无码精品亚洲日韩| 久久99精品国产麻豆宅宅| 久久香蕉国产线看观看99| 久久久久国色AV免费观看| 久久精品aⅴ无码中文字字幕不卡| 国内精品久久久久久99蜜桃 | 久久91精品综合国产首页| 久久精品国产亚洲Aⅴ香蕉 | 秋霞久久国产精品电影院| 久久只有这里有精品4| 久久精品国产99久久无毒不卡| 国内精品欧美久久精品| 亚洲国产精品无码久久久秋霞2 | 97久久天天综合色天天综合色hd| 久久国产高清一区二区三区| 九九久久自然熟的香蕉图片| 亚洲精品无码久久不卡| 国产精品美女久久久网AV| 久久精品人人做人人爽97| 伊人久久大香线蕉综合热线| 国产福利电影一区二区三区久久久久成人精品综合 | 国内精品久久久久影院网站 | 国产精品久久成人影院| 2021国内久久精品| 久久久WWW成人免费毛片| 91亚洲国产成人久久精品网址| 99久久99久久久精品齐齐| 伊人久久大香线焦AV综合影院| 亚洲国产精品成人AV无码久久综合影院| 美女写真久久影院| 狠狠色丁香婷婷久久综合不卡| 国产成人久久精品激情| 精品综合久久久久久888蜜芽| 人妻久久久一区二区三区| 中文字幕久久久久人妻| 99精品国产免费久久久久久下载| 一本综合久久国产二区| 香港aa三级久久三级老师2021国产三级精品三级在 | 亚洲综合精品香蕉久久网| 99久久精品免费看国产一区二区三区|