DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

main.cpp

#include "classes/fun.h"
int main() {
    Test::display("Hello makefile");
    return 0;
}

classes/fun.h

#include <iostream>
using namespace std;

class Test {
public:
    void static display(const char *);
};

classes/fun.cpp

#include "fun.h"
void Test::display(const char *str) {
    cout <<str <<endl;
}

classes/makefile

test.o:classes/fun.cpp
    g++ -c classes/fun.cpp -o test.o

makefile

test: test.o main.o
    g++ test.o main.o -o test

main.o:main.cpp
    g++ -c main.cpp -o main.o

include classes/makefile

clean:
    rm main.o test.o test

include classes/makefile中的include关键字就是引用其它的makefile,值得注意的是,在被引用的makefile文件中的代码,它的路径是相对于引用的makefile文件的路径(注意到test.o:classes/fun.cpp),思考一下:我可以把include classes/makefile这句写在开头吗?答案当然是不能,至于为什么,在Makefile第一讲:一个简单的Makefile

posted on 2015-11-07 16:57  DoubleLi  阅读(2275)  评论(0编辑  收藏  举报