LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 947|回复: 7

将2个各自独立的程序的编译过程写在makefile中,但是只编译了一个,why?

[复制链接]
发表于 2003-8-14 10:51:12 | 显示全部楼层 |阅读模式
2个程序毫无关系,它们的编译过程都写在同一个makefile文件中,但是只编译了一个,请问是什么原因,谢谢
发表于 2003-8-14 11:38:07 | 显示全部楼层
应该是你Makefile的问题
发表于 2003-8-14 11:40:28 | 显示全部楼层
可能需要加入这么一句吧

all: prog1 prog2
 楼主| 发表于 2003-8-14 12:25:44 | 显示全部楼层
加了这句了
 楼主| 发表于 2003-8-14 13:30:22 | 显示全部楼层

我把所有程序贴出来看看

(1)hello.c
#include<stdio.h>

int main(void)
{
        printf("Hello, Linux programming world!\n");
        return 0;
}
(2)helper.c
#include<stdio.h>

void msg(void)
{
        printf("This message sent from GuoRui.\n");
}
(3)helper.h
void msg(void);
(4)howdy.c
#include<stdio.h>
#include"helper.h"

int main(void)
{
        printf("Hello, Linux programming world!\n");
        msg();
        return 0;
}
(5)makefile
howdy: howdy.o helper.o helper.h
        gcc howdy.o helper.o -o howdy
howdy.o: howdy.c
        gcc -c howdy.c
helper.o: helper.c
        gcc -c helper.c

hello: hello.c
        gcc hello.c -o hello
       
all: howdy hello
小弟初学,望各位不吝赐教
 楼主| 发表于 2003-8-14 13:31:38 | 显示全部楼层

忘了说明

运行结果是:只编译了howdy,没有编译hello
发表于 2003-8-14 17:27:14 | 显示全部楼层
把all:howdy hello写到第一行试试。
make的规则是这样的,如果用make target指定目标,则只执行相应的目标。我相信你用make hello是完全可以单独编译hello的。但是在没有指定目标的情况下,make 就会执行makefile的第一个目标。这里自然就是howdy了。所以为了让make执行多个目标,常常要做一个假目标all,放在第一行。以便执行所有的目标。
 楼主| 发表于 2003-8-14 20:08:16 | 显示全部楼层
谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表