Forum : ST7/STM8
Original Post
Post Information | Post |
---|---|
November 4, 2010 - 9:13am
|
Hi everyone, Description of my problem: In a "File1.h" file, I defined a structure like that: sMyStruct gMyStruct; So in "File1.c", I use normaly the definition: And for example, I would like to make the same code in "main.c". But I have this error: I hope my english is not too bad. |
Hi Sylvain,
You should *not* place variable definitions (only declarations) in header files.
This means that "sMyStruct gMyStruct;" shoul dbe in a C file in your project.
Your code works fine if you respect this simple rule, we verified it in our Labs.
If you still have some problems, please send us the listing file produced by the compiler, and a copy of the *exact* error message you receive.
Regards,
Hi Bruno,
Thank you for this information.
Now it's ok when "sMyStruct gMyStruct;" is in C file.
It's strange because a simple var like "u8 toto;" in H file doesn't make an error when it use in other C file.....
I don't know if it's an ANSI C rule or not.
Regards.
Hi Sylvain,
If the given .h file is included in several C files, you will have a linker conflict (multiple definition), as each of the C file that includes the .h will try to define the same variable.
BR