delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/02/05/16:56:13

Message-ID: <3A7F202C.12549DCB@tinyworld.co.uk>
Date: Mon, 05 Feb 2001 21:50:36 +0000
From: KBZDj <KBZDj AT tinyworld DOT co DOT uk>
X-Mailer: Mozilla 4.72 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: A beginner's problem...!
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019