469,934 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

enum used in multiple compilation units

I have a file here with several enums:

#ifndef PLANARSEP_OPTIMIZE_H
#define PLANARSEP_OPTIMIZE_H
enum fund_cycle_behavior_t
{PASS_MODE_FIRST,
PASS_MODE_BEST,
PASS_MODE_ALL};

enum optimization_criterium_t
{OPTIMIZE_NOTHING,
OPTIMIZE_SEPARATOR,
OPTIMIZE_BALANCE,
OPTIMIZE_RATIO};
enum end_opt_t
{END_OPTIMIZE_NOTHING,
END_OPTIMIZE_EXPEL,
END_OPTIMIZE_DUL_MEN,
END_OPTIMIZE_EXPEL_DUL_MEN,
END_OPTIMIZE_DUL_MEN_EXPEL};

#endif

Before, the enums didn't have a name and everything worked.

Now that I included the names (in order to store the values in variables
having the enum type), I get the following error when linking:

Link separator
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x0): multiple
definition of `fund_cycle_behavior_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x0): first defined here
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x4): multiple
definition of `optimization_criterium_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x4): first defined here
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x8): multiple
definition of `end_opt_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x8): first defined here
libseparator_time.a(complex_separation_time.o):(.b ss+0x0): multiple
definition of `fund_cycle_behavior_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x0): first defined here
libseparator_time.a(complex_separation_time.o):(.b ss+0x4): multiple
definition of `optimization_criterium_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x4): first defined here
libseparator_time.a(complex_separation_time.o):(.b ss+0x8): multiple
definition of `end_opt_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x8): first defined here
collect2: ld returned 1 exit status

I haven't changed any other code yet ...

Can't I declare an enum in a header file included in multiple
compilation units?
Oct 25 '06 #1
3 1711
Jens Müller wrote:
I have a file here with several enums:

#ifndef PLANARSEP_OPTIMIZE_H
#define PLANARSEP_OPTIMIZE_H
enum fund_cycle_behavior_t
{PASS_MODE_FIRST,
PASS_MODE_BEST,
PASS_MODE_ALL};

enum optimization_criterium_t
{OPTIMIZE_NOTHING,
OPTIMIZE_SEPARATOR,
OPTIMIZE_BALANCE,
OPTIMIZE_RATIO};
enum end_opt_t
{END_OPTIMIZE_NOTHING,
END_OPTIMIZE_EXPEL,
END_OPTIMIZE_DUL_MEN,
END_OPTIMIZE_EXPEL_DUL_MEN,
END_OPTIMIZE_DUL_MEN_EXPEL};

#endif

Before, the enums didn't have a name and everything worked.

Now that I included the names (in order to store the values in variables
having the enum type), I get the following error when linking:

Link separator
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x0): multiple
definition of `fund_cycle_behavior_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x0): first defined here
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x4): multiple
definition of `optimization_criterium_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x4): first defined here
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x8): multiple
definition of `end_opt_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x8): first defined here
libseparator_time.a(complex_separation_time.o):(.b ss+0x0): multiple
definition of `fund_cycle_behavior_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x0): first defined here
libseparator_time.a(complex_separation_time.o):(.b ss+0x4): multiple
definition of `optimization_criterium_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x4): first defined here
libseparator_time.a(complex_separation_time.o):(.b ss+0x8): multiple
definition of `end_opt_t'
libseparator_time.a(PlanarSeparator_time.o):(.bss+ 0x8): first defined here
collect2: ld returned 1 exit status

I haven't changed any other code yet ...

Can't I declare an enum in a header file included in multiple
compilation units?
Yes, you can. Please consult
http://parashift.com/c++-faq-lite/ho...t.html#faq-5.8 in posting
code that doesn't work. The summary: provide a minimal but *complete*
example that we can cut and paste unchanged into our editors that
demonstrates your problem.

Cheers! --M

Oct 25 '06 #2
Jens Müller wrote:
I have a file here with several enums:

[...]

Before, the enums didn't have a name and everything worked.

Now that I included the names (in order to store the values in
variables having the enum type), I get the following error when
linking:
Link separator
libseparator_time.a(g_planar_separator_time.o):(.b ss+0x0): multiple
definition of `fund_cycle_behavior_t'
[..]

I haven't changed any other code yet ...

Can't I declare an enum in a header file included in multiple
compilation units?
Should be able to, an 'enum' declaration only defines a unique type.

You need to consult your compiler documentation. Apparently it
thinks your enums are objects or something, and we can't really
help you, linking errors are not defined in C++. Are you sure the
code you posted is what your code looks like? Do you think you
could follow the recommendations of FAQ 5.8?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 25 '06 #3
Victor Bazarov wrote:
>>Can't I declare an enum in a header file included in multiple
compilation units?


Should be able to, an 'enum' declaration only defines a unique type.
OK, the fact that it _should_ work is enough for the moment. Tried a
simple test program with a common enum type in both of two object files,
everything works as expected.
You need to consult your compiler documentation. Apparently it
thinks your enums are objects or something, and we can't really
help you, linking errors are not defined in C++. Are you sure the
code you posted is what your code looks like?
Do you think you
could follow the recommendations of FAQ 5.8?
Sorry, not currently, it's a not very small and quite bad-structured
project I am beginning to dive in.

I have just added a name to one of the enum types, and it worked. Second
one, still worked. Third one - works.

WTF?! Sorry to have bothered you ...

Only explanation I have at the moment: Wrong dependencies and object
code lying around having an old definition ... But I really don't know.
Oct 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Adam Blair | last post: by
2 posts views Thread by Randy | last post: by
5 posts views Thread by Francois Grieu | last post: by
9 posts views Thread by subramanian | last post: by
94 posts views Thread by Samuel R. Neff | last post: by
9 posts views Thread by ramsatishv | last post: by
6 posts views Thread by The Architect | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.