• <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
            數(shù)據(jù)加載中……

            帶依賴關(guān)系的makefile簡易例子

            # makefile 開始

            # 編譯相關(guān)的選項
            CC = g++
            CPPFLAG =

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

            # 與源文件對應(yīng)的目標(biāo)文件和依賴文件
            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實現(xiàn)這個功能,在這里我編寫了print.exe實現(xiàn)該功能。
            %.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 結(jié)束

             

            // print.c 開始

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

            // print.c 結(jié)束

             

            // main.cpp 開始

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

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

            // main.cpp 結(jié)束

             

            // test_class.hpp 開始

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

            #endif // TEST_CLASS_HPP

            // test_class.hpp 結(jié)束

             

            // test_class.cpp 開始

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

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

            // test_class.cpp 結(jié)束

             

            // test_func.hpp 開始

            #ifndef TEST_FUNC_HPP
            #define TEST_FUNC_HPP

            void Print();

            #endif // TEST_FUNC_HPP

            // test_func.hpp 結(jié)束

             

            // test_func.cpp 開始

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

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

            // test_func.cpp 結(jié)束

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


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久毛片免费看一区二区三区| 久久久久波多野结衣高潮| 久久精品国产欧美日韩| 久久精品国产精品青草| 国产精品久久久久9999| 婷婷久久综合九色综合绿巨人| 2021久久精品免费观看| 久久91精品国产91久久户| 激情五月综合综合久久69| 精品久久久中文字幕人妻| 久久亚洲AV成人无码电影| 久久久久综合中文字幕| 一本色道久久88—综合亚洲精品| 久久精品一区二区影院| 午夜久久久久久禁播电影| 久久久久久久综合综合狠狠| 久久精品国产亚洲av麻豆蜜芽| 久久精品国产只有精品2020| 久久亚洲2019中文字幕| 久久免费线看线看| 亚洲va久久久噜噜噜久久| 一本色道久久88加勒比—综合| 久久久久亚洲AV无码专区体验| 国产成人无码精品久久久性色| 精品久久一区二区三区| 久久久久亚洲AV片无码下载蜜桃| 精品免费久久久久国产一区| 97热久久免费频精品99| 色综合久久久久综合体桃花网| 亚洲一区精品伊人久久伊人| 国产精品久久久久蜜芽| 精品国产91久久久久久久a| 国产99久久九九精品无码| 久久精品中文字幕第23页| 国产91色综合久久免费| 97久久精品无码一区二区| 狠狠精品久久久无码中文字幕| 国产精品乱码久久久久久软件| 国产一区二区久久久| 亚洲中文字幕久久精品无码APP | 亚洲综合伊人久久综合|