深入浅出 Makefile 简单实现

来源:互联网 发布:wamp php 环境变量 编辑:程序博客网 时间:2024/05/22 00:48

最近在看makefile规则,简单写了一个sample code 验证了一把

首先是代码目录架构,有A /B /C 三个文件夹:


A文件夹中的代码如下:

Ahello.c

#include <stdio.h>void ahello(const char *name){    printf("----AAAA---I am in Hello %s!\n", name);}
Ahello.h
void ahello(const char *name);



C文件夹中的代码如下:

Chello.c

#include <stdio.h> void chello(const char *name){    printf("---CCCC---I am in Hello %s!\n", name);}
Chello.h

void chello(const char *name);



B文件夹中的代码如下:

main.c:

#include "../A/Ahello.h"#include "../C/Chello.h"int main(){    ahello("everyone");    chello("everyone");    return 0;}
Makefile;

valuable:=main.o ../A/Ahello.o ../C/Chello.ohello:$(valuable)        gcc -o hello $(valuable)main.o:main.c        gcc -c main.cAhello.o:../A/Ahello.c        gcc -c ../A/Ahello.cChello.o:../C/Chello.c        gcc -c ../C/Chello.cclean:        rm hello $(valuable)

在B中执行make 命令生成如下的目录结构:



执行./hello 输出:
----AAAA---I am in Hello everyone!
---CCCC---I am in Hello everyone!


参考博客:http://blog.csdn.net/ruglcc/article/details/7814546/#t30

0 0
原创粉丝点击