求教:多级目录的makefile要怎么写?

nf110907 2011-11-12 10:49:40
例如:建立一个文件夹 :m
m中包含:main.c 文件夹 a 文件夹 b
//main.c
#include <stdio.h>
#include "a.h"
#include "b.h"
int main(void)
{
a();
b();
printf("and thanks!\n");
}


文件夹 a
//a.h
#ifndef _A_H_
#define _A_H_
void a();
#endif


//a.c
#include<stdio.h>
#include"a.h"

{
printf("hello! \n");
}

文件夹 b
//b.h
#ifndef _B_H_
#define _B_H_
void b();
#endif


//b.c
#include<stdio.h>
#include"b.h"

{
printf("everyone. \n");
}



写一个像这样比较简单的程序,文件夹 a 和 b 还有 m 里面的 makefile 要怎么写啊?各位高手帮帮忙啊,小弟初学,打字也很辛苦的!谢谢大家!
...全文
182 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
李迟 2011-11-13
  • 打赏
  • 举报
回复
我的做法是这样:
1、将子目录(a、b)下的代码编译成静态库
2、在m目录的Makefile中连接这些静态库,生成可执行文件。

缺点:有多少个静态库,要显式指定静态库。

链接:
http://www.latelee.org/programming-under-linux/113-multi-makefile-for-app.html
希望对楼主有帮助。
翔云123456 2011-11-13
  • 打赏
  • 举报
回复
建议参考linux内核里面的写法
justkk 2011-11-13
  • 打赏
  • 举报
回复
makefile中指定头文件查找路径
gcc -Ia -Ib ..

另外,可以使用变量VPATH来定义源文件的查找路径
VPATH=a:b:.

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧