[嵌入式linux] 求助Makefile文件

[复制链接]
 楼主| nsnwz 发表于 2007-5-23 15:12 | 显示全部楼层 |阅读模式
/*maht.c文件*/
#include <stdio.h>
#include"first.h"
int main()
{
        printf("%d\n",sub(2,3)) ;
        printf("good!\n") ;
}

/*first.c文件*/
#include"first_first.h"
int sub(int a, int b)
{
        return first_add(a,b) ;
}

/*firstfirst.c文件*/
int first_add(int a, int b)
{
        return a+b ;
}

/*Makefile文件*/
all: math.o
math.o:math.c  first.o
        gcc -o math.o math.c first.o
first.o:first.c firstfirst.c first_first.h
        gcc -c first.c  firstfirst.c
clean:
        \rm *.o

运行make,提示错误:first.o: In function `sub':first.c:(.text+0x14):对‘first_add’未定义的引用
collect2: ld 返回 1

请高手指教一 下,这个Makefile文件出错在那里。
 楼主| nsnwz 发表于 2007-5-23 16:58 | 显示全部楼层

高手指教

高手指教,急!
high 发表于 2007-5-24 01:42 | 显示全部楼层

.

/*first.c文件*/
#include"first_first.h"
extern int first_add(int a, int b);
int sub(int a, int b)
{
        return first_add(a,b) ;
}
康飞等丝丝 发表于 2007-5-29 00:09 | 显示全部楼层

turmary 发表于 2007-5-30 02:46 | 显示全部楼层

可以这样儿

在first_first.h中加入
int first_add(int a, int b);

在firstfirst.c中加入
#include"first_first.h"

这样儿就是标准用法.定义与使用的地方均包含这个头文件.
frankfly 发表于 2007-6-3 19:22 | 显示全部楼层

应该要加路径吧

woyaya 发表于 2007-7-9 16:50 | 显示全部楼层

re

all: math.o
math.o:math.c  first.o
        gcc -o math.o math.c first.o <<<<<<<<<<<<<<<缺少first_first.o
first.o:first.c firstfirst.c first_first.h
        gcc -c first.c  firstfirst.c
clean:
        \rm *.o
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

13

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部