Why do I get all those mult. defin errors
Matthew Majka
mmajka@cs5.dasd.honeywell.com
Fri Oct 15 13:09:00 GMT 1999
On Fri, 15 Oct 1999, hihihi wrote:
> Scott wrote:
> >
> > When I compile gcc -g foo foo.c I get all kinds of multiple definition
> > errors.
>
> I have a related problem.
>
> If have two file's included in my program :
>
> #include <i2c_k8000.h>
> #include <linux_k8005.h>
>
> In both file is are :
>
> extern void SelectI2CprinterPort(void);
> extern void I2CBusNotBusy(void);
>
> And both in i2c_k8000.c and linux_k8005.c are a :
>
> void outport(void)
>
> And a lot more.
>
>
> When i compile with :
>
> gcc -O3 ifndef-001.c i2c_k8000.c linux_k8005_007.c -o ifndef-001.e -I
> /home/rien/k8005/development/007/
>
> I get :
>
> /tmp/cca007123.o: In function `outport':
> /tmp/cca007123.o(.text+0x750): multiple definition of `outport'
> /tmp/cca007122.o(.text+0x24f0): first defined here
> /tmp/cca007123.o: In function `SelectI2CprinterPort':
> /tmp/cca007123.o(.text+0xf20): multiple definition of
> `SelectI2CprinterPort'
> /tmp/cca007122.o(.text+0x2d00): first defined here
> ld: Warning: size of symbol `SelectI2CprinterPort' changed from 201 to
> 134 in /tmp/cca007123.o
> /tmp/cca007123.o: In function `I2CBusNotBusy':
> /tmp/cca007123.o(.text+0xfb0): multiple definition of `I2CBusNotBusy'
> /tmp/cca007122.o(.text+0x2dd0): first defined here
>
>
> i have also tried it with this in both .h files :
>
> #ifndef
> #define loaded
>
> extern void SelectI2CprinterPort(void);
> extern void I2CBusNotBusy(void);
>
> #endif
>
> But that does not solve it, same errors.
>
> Is there a way to solve it ??
> That would be great..
If I understand you correctly, you have two header files
with some identical prototypes in them and you include them
both in the same file. In addition, you have two C files
containing functions of the same name.
Concerning the header files, I can understand why you would
have the same function prototypes in two different header
files, but I cannot understand why you would then include
both of them.
As for the C files, since none of your functions are
declared 'static' they are visible globally.
If you have I2CBusNotBusy() in two header files and two C
files (and you are #including and compiling both at the
same time), how is the compiler supposed to know which one
you want to use?
More information about the Gcc-help
mailing list