Enum definition and declaration

Discussions and support about ChibiStudio, the free development environment for ARM.
Post Reply
duracell
Posts: 24
Joined: Tue Jul 05, 2016 8:55 am
Has thanked: 4 times
Been thanked: 1 time

Enum definition and declaration

Post by duracell »

Hi to all,

I have a small problem using enums with chibistudio.



If I compile my project with the following piece of code:
[mod=duracell]typedef enum
{CLOSE_VALVE,
OPEN_VALVE} valve_state;
//valve_state valve1;[/mod]

The compier does its job without errors.

If I de-comment the line of the declaration of valve1 I have the following error:
^
[mod=duracell]Linking build/ch.elf
build/obj/main.o (symbol from plugin): In function `valve1':
(.text+0x0): multiple definition of `valve1'
build/obj/extlib.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [build/ch.elf] Error 1[/mod]


I don't have other declarations of valve1, so I don't know which C rule I am breaking :(


Thanks to all for reading.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Enum definition and declaration

Post by Giovanni »

Hi,

Note that it is a linker error, probably you have that same symbol in another module OR that code is placed in a header, placing variable declarations in headers creates an instance each time the header is included.

Giovanni
duracell
Posts: 24
Joined: Tue Jul 05, 2016 8:55 am
Has thanked: 4 times
Been thanked: 1 time

Re: Enum definition and declaration

Post by duracell »

Thank you very much Giovanni, yes the declaration was in the header.

I did not know about this rule, I moved the declaration in the .c and now it is ok!
Post Reply