Results 1 to 5 of 5

Thread: Multiple decleration problem

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Multiple decleration problem

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple decleration problem

    What about forward declaration of the var type, and use a pointer to it.
    Something like:

    Qt Code:
    1. struct SomeOtherStruct;
    2.  
    3. class MyClass
    4. {
    5. ...
    6. SomeOtherStruct* other;
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multiple decleration problem

    I find it very acceptable, and was one of the first things I tried...
    For some reason it didn't work...
    But I just tried again, and it did...
    I probably need to take a break...
    Thanks.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple decleration problem

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multiple decleration problem

    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...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.