Page 1 of 1

Enum definition and declaration

Posted: Fri Sep 09, 2016 3:55 pm
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.

Re: Enum definition and declaration

Posted: Fri Sep 09, 2016 4:11 pm
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

Re: Enum definition and declaration

Posted: Fri Sep 09, 2016 4:17 pm
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!