Mail Archives: djgpp/2001/02/05/16:56:13
I am a c/c++ novice, trying to teach myself with the aid of a couple of
books and DJGPP and RHIDE. I have just been trying my first attempt at
including my own header files - but cannot get anywhere. So please can
anyone help - and sorry for bringing up what is probably a very simple
problem. The problem is described below - could any replies be sent
direct to me because I have not subscribed to the mailing list.
PROBLEM
Using RHIDE, I have 2 c files each of which #includes a header file. The
code is straight from a Teach Yourself C book. The source files compile,
but I cannot link them to create an EXE. When building (compiling and
linking) the files I get the following message:
Compiling: calc.c
no errors
Compiling: list2101.c
no errors
Creating test.exe
Error: calc.o: In function 'sqr':
calc.c(4) Error:multiple definition of 'sqr'
o:calc.c(4) Error:first defined here
Error: collect2: ld returned 1 exit status
There were some errors
The source code of the 3 files is:
/*list2101.c*/
#include <stdio.h>
#include "calc.h"
int main()
{
int x;
printf("Enter an integer value: ");
scanf("%d", &x);
printf("\nThe square of %d is %ld.\n", x, sqr);
return;
}
------------------------------
/*calc.c*/
#include "calc.h"
long sqr(int x)
{
return ((long)x * x);
}
-------------------------------
/*calc.h*/
long sqr(int x);
Any help is greatly appreciated.
Bruce Carlisle
- Raw text -