structure redefinition error

D

dust

Hi,

Pls help me solve the compilation error:

In file included from /some/path/to/header1.h:1,
from /some/path/to/header2.h:15,
from //some/path/to/header3.h:46,
from //some/path/to/header4.h:1,
from //some/path/to/header5.h:4:
/actual/path/to/header6.h:107: redefinition of `struct vmac_addr'
Exception: error status 1 from /usr/bin/gcc
make: *** [OBJ/sim/object_file.o] Error 1

The compiler is complaining about multiple definition but not saying
where else it has been redeclared/redefined. Also the notable thing is
in the code the structure has been 'typedef' as:

typedef struct vmac_addr {
union {
u_int8_t mbyte[6];
u_int16_t mword[3];
} v;
} vMAC_ADDR;

But used as struct vmac_addr itself and not with typedef'ed
identifier. How to identify where the structure is redefined/
redeclared?

Thanks
Dust
 
A

Alf P. Steinbach /Usenet

* dust, on 28.02.2011 07:12:
Hi,

Pls help me solve the compilation error:

In file included from /some/path/to/header1.h:1,
from /some/path/to/header2.h:15,
from //some/path/to/header3.h:46,
from //some/path/to/header4.h:1,
from //some/path/to/header5.h:4:
/actual/path/to/header6.h:107: redefinition of `struct vmac_addr'
Exception: error status 1 from /usr/bin/gcc
make: *** [OBJ/sim/object_file.o] Error 1

The compiler is complaining about multiple definition but not saying
where else it has been redeclared/redefined.

Most probably one or more header doesn't have a proper include guard, so that
the text of [header6.h] is included twice.

Also the notable thing is
in the code the structure has been 'typedef' as:

typedef struct vmac_addr {
union {
u_int8_t mbyte[6];
u_int16_t mword[3];
} v;
} vMAC_ADDR;

But used as struct vmac_addr itself and not with typedef'ed
identifier. How to identify where the structure is redefined/
redeclared?

Start by checking include guards.

You can do this by creating a file that only includes [header6.h], then if that
works change it to include [header5.h] and so on.

If that doesn't identify the problem then it may be that you actually have
multiple definitions. Then use some tool (like, your editor) to search through
the sources.


Cheers & hth.,

- Alf
 
S

SG

Pls help me solve the compilation error:

In file included from /some/path/to/header1.h:1,
                 from /some/path/to/header2.h:15,
                 from //some/path/to/header3.h:46,
                 from //some/path/to/header4.h:1,
                 from //some/path/to/header5.h:4:
/actual/path/to/header6.h:107: redefinition of `struct vmac_addr'
Exception: error status 1 from /usr/bin/gcc
make: *** [OBJ/sim/object_file.o] Error 1

The compiler is complaining about multiple definition but not saying
where else it has been redeclared/redefined.

If you have defined this type in only one place (header1.h) then the
only explanation would be that you accidentally include this header
more than once into a translation unit (either directly or
indirectly). The solution to this are "include guards".
Also the notable thing is
in the code the structure has been 'typedef' as:

typedef struct vmac_addr {
  union {
    u_int8_t    mbyte[6];
    u_int16_t   mword[3];
  } v;
} vMAC_ADDR;

Keep in mind that union-based "type punning" is a GCC extension.
According to the C++ standard does not define a particular behaviour
in this case.

Cheers!
SG
 
D

dust

* dust, on 28.02.2011 07:12:
Pls help me solve the compilation error:
In file included from /some/path/to/header1.h:1,
                  from /some/path/to/header2.h:15,
                  from //some/path/to/header3.h:46,
                  from //some/path/to/header4.h:1,
                  from //some/path/to/header5.h:4:
/actual/path/to/header6.h:107: redefinition of `struct vmac_addr'
Exception: error status 1 from /usr/bin/gcc
make: *** [OBJ/sim/object_file.o] Error 1
The compiler is complaining about multiple definition but not saying
where else it has been redeclared/redefined.

Most probably one or more header doesn't have a proper include guard, so that
the text of [header6.h] is included twice.
Also the notable thing is
in the code the structure has been 'typedef' as:
typedef struct vmac_addr {
   union {
     u_int8_t    mbyte[6];
     u_int16_t   mword[3];
   } v;
} vMAC_ADDR;
But used as struct vmac_addr itself and not with typedef'ed
identifier. How to identify where the structure is redefined/
redeclared?

Start by checking include guards.

You can do this by creating a file that only includes [header6.h], then if that
works change it to include [header5.h] and so on.

If that doesn't identify the problem then it may be that you actually have
multiple definitions. Then use some tool (like, your editor) to search through
the sources.

Cheers & hth.,

- Alf

Manually found that all the header files has 'include gaurds'. Also
tried with second method by including a header6.h in a temp.cpp file.
I got this error:

In file included from /path/to/header1.h:15,
from /path/to/header2.h:46,
from /path/to/some/other/header.h:1,
from /path/to/header6.h:1,
from /path/to/temp.cpp:1:
/path/to/header/whih/is/including/(header6.h).h:52: '
vMAC_ADDR' is used as a type, but is not defined as a type.
/path/to/header/whih/is/including/(header6.h).h:54: `
MAX_VRIDS' was not declared in this scope
/path/to/header/whih/is/including/(header6.h).h:54: confused by
earlier errors, bailing out
Exception: error status 1 from /usr/bin/g++
make: *** [OBJ/sim/temp.o] Error 1

Now instead of redefinition error, g++ is complaining about no
definition, even though temp.cpp has #included <header6.h> in which
this struct has been declared(confirmed)...

Thanks
Dust
 
S

SG

[...]
Now instead of redefinition error, g++ is complaining about no
definition, even though temp.cpp has #included <header6.h> in which
this struct has been declared(confirmed)...

There is not a lot we can do except for *guessing* what you might have
done unless you show more code. Try to reduce your problem to a short
example. You might also want to "compile" temp.cpp with the option -E
(see compiler documentation) and check the result.

Cheers!
SG
 
G

Geoff

Hi,

Pls help me solve the compilation error:

In file included from /some/path/to/header1.h:1,
from /some/path/to/header2.h:15,
from //some/path/to/header3.h:46,
from //some/path/to/header4.h:1,
from //some/path/to/header5.h:4:
/actual/path/to/header6.h:107: redefinition of `struct vmac_addr'
Exception: error status 1 from /usr/bin/gcc
make: *** [OBJ/sim/object_file.o] Error 1

The compiler is complaining about multiple definition but not saying
where else it has been redeclared/redefined. Also the notable thing is
in the code the structure has been 'typedef' as:

typedef struct vmac_addr {
union {
u_int8_t mbyte[6];
u_int16_t mword[3];
} v;
} vMAC_ADDR;

But used as struct vmac_addr itself and not with typedef'ed
identifier. How to identify where the structure is redefined/
redeclared?

Thanks
Dust

I this some kind of open-source project available on the web? If so,
please post a link to the sources so they can be inspected. If not, I
suggest you take it up with your project lead.

Generally, multiple definitions are most easily caused when you are
including the header containing the definition in multiple files
without a macro guard. In this case, header6.h:107 is the
redefinition. If that is the only place vmac_addr is defined in the
project then that file is the one being included multiple times.
 
B

Balog Pal

dust said:
But used as struct vmac_addr itself and not with typedef'ed
identifier. How to identify where the structure is redefined/
redeclared?

Ask your compiler to produce the 'preprocessor output', and search that file
for the definition.
 
D

dust

Pls help me solve the compilation error:
In file included from /some/path/to/header1.h:1,
                from /some/path/to/header2.h:15,
                from //some/path/to/header3.h:46,
                from //some/path/to/header4.h:1,
                from //some/path/to/header5.h:4:
/actual/path/to/header6.h:107: redefinition of `struct vmac_addr'
Exception: error status 1 from /usr/bin/gcc
make: *** [OBJ/sim/object_file.o] Error 1
The compiler is complaining about multiple definition but not saying
where else it has been redeclared/redefined. Also the notable thing is
in the code the structure has been 'typedef' as:
typedef struct vmac_addr {
 union {
   u_int8_t    mbyte[6];
   u_int16_t   mword[3];
 } v;
} vMAC_ADDR;
But used as struct vmac_addr itself and not with typedef'ed
identifier. How to identify where the structure is redefined/
redeclared?
Thanks
Dust

I this some kind of open-source project available on the web? If so,
please post a link to the sources so they can be inspected. If not, I
suggest you take it up with your project lead.

Generally, multiple definitions are most easily caused when you are
including the header containing the definition in multiple files
without a macro guard. In this case, header6.h:107 is the
redefinition. If that is the only place vmac_addr is defined in the
project then that file is the one being included multiple times.- Hide quoted text -

- Show quoted text -

hmm....got where it has been redined....I ran the same compilation in
another clearcase server which wasn't yet synched with my clearcase.
It showed where it is redefined


Thanks to all :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top