PDA

View Full Version : Multiple decleration problem



high_flyer
18th May 2007, 18:33
Hi,

I have a strange problem regarding multiple decleration error:
At link time I get the following:

linking libqhkp.so.1.0.0 (g++)
obj/moc_qhkp.o:(.bss+0x0): multiple definition of `et_hkp_drv_type'
obj/qhkp.o:(.bss+0x0): first defined here
obj/moc_qhkp.o:(.bss+0x4): multiple definition of `st_hkp_drv_act_out'
obj/qhkp.o:(.bss+0x4): first defined here
obj/moc_qhkp.o:(.bss+0x5): multiple definition of `st_hkp_drv_act_out_all'
obj/qhkp.o:(.bss+0x5): first defined here
obj/moc_qhkp.o:(.bss+0x7): multiple definition of `st_hkp_drv_act_in'
obj/qhkp.o:(.bss+0x7): first defined here
obj/moc_qhkp.o:(.bss+0x8): multiple definition of `st_hkp_drv_act_in_all'

the error complains about sruct definitions (not as typedef) which are all located in a header file.
The header file is gourded by the usual #ifndef _headerName_.
In addtion, note that the the second definition is in the moc file.
But I checked and the moc file has nowhere these sturct names in it... :confused:
I tried playing with the include order but that didn't help.
Any idea's how I can debug and sort this out?

The problem occurs only when I put the said header in my class header, and I have to, since I am using a memebr variable which is one of these structs.
If the header is used only in the implementation file of the class, it compiles and links ok.
(of course, I can't use that member variable then)

Qt4.2.1 SUSE10.1 .

Thanks.

marcel
18th May 2007, 18:41
What about forward declaration of the var type, and use a pointer to it.
Something like:



struct SomeOtherStruct;

class MyClass
{
...
SomeOtherStruct* other;
...
}

This way you don't have to include the header here, but only in the source file.

If you don't find this acceptable, then we can see some relevant code?

Regards.

high_flyer
18th May 2007, 18:57
I find it very acceptable, and was one of the first things I tried...
For some reason it didn't work...:o
But I just tried again, and it did...
I probably need to take a break...:rolleyes:
Thanks.

marcel
18th May 2007, 19:05
Nice to hear it works.
But there has to be a workaround ( or a real solution - always has to be ) to the errors you were getting when you included the header.

high_flyer
21st May 2007, 09:07
I totally agree.
But I just don't have the time to seach for the "real solution".
I did try all the regular stuff as I mentioned above.
There are two strange things in the case:
1. even through there is the #ifndef gourd at in the header, a multiple definition error occurs.
2. the moc file complains, but has nowhere in it any of the said symbols, at least no in the source file.
I could look in the o file I guess... but even then it will only reafiem the error, not its cause.

My guess is that the multiple decleration error is not the real error, but some "side effect" of something else - the question is what...