【发布时间】:2010-09-27 16:25:47
【问题描述】:
我有问题。我写了这段代码,啊。 a.c 和 main.c:
文件:a.h
#ifndef _a_H
#define _a_H
int poly (int a, int b, int c, int x);
int square (int x)
{
return x*x;
}
#endif // _a_H
文件:a.c
#include "a.h"
int poly (int a, int b, int c, int x)
{
return a*square(x) + b * x +c;
}
文件:main.c
#include <stdio.h>
#include "a.h"
int main()
{
int p1 = poly1 (1 ,2 , 1, 5);
int p2 = poly2 (1 ,1 , 3, 5);
printf ("p1 = %d, p2 = %d\n", p1, p2);
return 0;
}
我得到了一个错误:
/tmp/ccKKrQ7u.o:在函数'square'中:
main.c:(.text+0x0): 'square'的多重定义
/tmp/ccwJoxlY.o:a.c:(.text+0x0): 首先在这里定义
collect2: ld 返回 1 个退出状态
所以我将函数 square 的实现移到了 a.c 文件中,它可以工作了。
有人知道为什么吗?
感谢
【问题讨论】: