• <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 閱讀(724) 評論(0)  編輯 收藏 引用


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


            伊人久久大香线蕉影院95| 国产呻吟久久久久久久92| 久久99精品久久久久久不卡| 久久精品成人免费网站| 国内精品久久久久久久影视麻豆| 久久综合九色综合久99| 久久成人精品| 久久精品一本到99热免费| 99久久国产综合精品成人影院| 久久久久无码精品国产app| 亚洲&#228;v永久无码精品天堂久久 | 午夜精品久久久久久99热| 精品久久香蕉国产线看观看亚洲 | 亚洲国产精品无码久久| 久久久久久综合一区中文字幕| 日韩一区二区三区视频久久| 69SEX久久精品国产麻豆| 久久精品国产福利国产秒| 久久久久久噜噜精品免费直播| 久久久久久精品成人免费图片| 伊人久久综在合线亚洲2019 | 久久久老熟女一区二区三区| 国产精品熟女福利久久AV| 少妇内射兰兰久久| 伊人久久大香线蕉成人| 久久久久九九精品影院| 99久久亚洲综合精品网站| 久久精品a亚洲国产v高清不卡| 亚洲人成网站999久久久综合| 国内精品久久久久久野外| 伊人久久大香线蕉av不变影院| 久久久黄片| 久久久91人妻无码精品蜜桃HD| 亚洲成色999久久网站| 69久久夜色精品国产69| 久久99精品久久久久久动态图| 无码AV中文字幕久久专区| 久久99精品久久久大学生| 一本色道久久99一综合| 国产69精品久久久久久人妻精品| 久久久久亚洲AV成人网人人网站|