Mail Archives: djgpp/1998/07/29/21:34:20
On 29 Jul 98 at 9:52, Bruno Barberi Gnecco wrote:
> I wrote a program made of several files, and when I tried to compile (using
> RHIDE), it returned:
> Error: config.o: In function `loadconfig':
> config.c(8) Error: multiple definition of `loadconfig'
> o:config.c(8) Error: first defined here
> Error: config.o: In function `newconfig':
> config.c(24) Error: multiple definition of `newconfig'
> o:config.c(24) Error: first defined here
> Error: config.o(.data+0x0):config.c: multiple definition of `defaultprefs'
> Error: config.o(.data+0x0):config.c: first defined here
> etc...
> For all functions! The I tried to compile using gcc - o file.exe *.o, and the
> result was:
>
> main.o(.data+0x0):main.c: multiple definition of `defaultprefs'
> config.o(.data+0x0):config.c: first defined here
> menu.o: In function `about':
> menu.c:386: multiple definition of `about'
> main.o(.data+0x70):main.c: first defined here
> d:/djgpp/bin/ld.exe: Warning: type of symbol `_about' changed from 114 to 33 in
> menu.o
> menu.o(.data+0x0):menu.c: multiple definition of `defaultprefs'
> config.o(.data+0x0):config.c: first defined here
>
> What's the problem?
It's hard to say without seeing what you were trying to compile.
Make the following three files:
--8<--------- file1.c
#include "file2.h"
int main()
{
func();
return 0;
}
--8<--------- file2.c
#include <stdio.h>
#include "file2.h"
void func()
{
puts ("Hello, cruel world!");
}
--8<--------- file2.h
void func();
--8<---------
To compile these, you'd type (minimum switches):
gcc -c file1.c
gcc -c file2.c
and to link:
gcc file1.o file2.o -o file.exe
If any of these commands give you problems then something is wrong
with your installation. Otherwise, you need to try to find out what
is wrong with your code. From the warnings and errors I'd guess that
you either have definitions in header files (which you shouldn't do;
only put declarations in header files, with definitions in exactly
one source file), or you're including one source file in another, or
linking one file into the project twice. Maybe you're just
accidentally trying to use different variables in different source
files, but giving the variables the same name. If this is the case
then you might be able to make them static (i.e. local to one source
file), or rename them.
--
george DOT foot AT merton DOT oxford DOT ac DOT uk
- Raw text -