Enum definition and declaration

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

Enum definition and declaration

Postby duracell » Fri Sep 09, 2016 3:55 pm

Hi to all,

I have a small problem using enums with chibistudio.



If I compile my project with the following piece of code:
 ! Message from: duracell
typedef enum
{CLOSE_VALVE,
OPEN_VALVE} valve_state;
//valve_state valve1;


The compier does its job without errors.

If I de-comment the line of the declaration of valve1 I have the following error:
^
 ! Message from: 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



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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Enum definition and declaration

Postby Giovanni » Fri Sep 09, 2016 4:11 pm

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

Postby duracell » Fri Sep 09, 2016 4:17 pm

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!


Return to “ChibiStudio”

Who is online

Users browsing this forum: No registered users and 6 guests