hey :)
i have a problem. i wrote this code, a.h. a.c and the main.c:
file: 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
file: a.c
#include "a.h"
int poly (int a, int b, int c, int x)
{
return a*square(x) + b * x +c;
}
file: 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;
}
and i got an error:
/tmp/ccKKrQ7u.o: In function 'square':
main.c:(.text+0x0): multiple definition of 'square'
/tmp/ccwJoxlY.o:a.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
so i moved the implementation of the function square to the a.c file and it works.
does any one know why?
thanx