Makefile第四讲:include 引用其它makefile文件

2016-09 睿丰德RFID软件系统集成商
睿丰德科技 专注RFID识别技术和条码识别技术与管理软件的集成项目。质量追溯系统、MES系统、金蝶与条码系统对接、用友与条码系统对接

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

RFID管理系统集成商 RFID中间件 条码系统中间层 物联网软件集成

给我们留言

电话咨询
邮件咨询
在线地图
微信15622149977