Forum : ST7/STM8
Original Post
Post Information | Post |
---|---|
April 18, 2012 - 1:18pm
|
Hi, I want to use a global variable in 2 c-files. I wrote a headerfile globalvar.h with and included it in program1.c and program2.c Regards |
Hi,
That's an easy one: You should never have a definition (a declaration that "creates" an object) in a header file.
The trick is to have all object *declarations* in a header file, and the object *definitions* in a C file (usually with the same name as the header).
So in your case, in file globalvar.h:
And in file globalvar.c:
That's it!
Hi,
Thanks for your answer. In this case I have to write each variable in two files.
In WinAVR I included only the globalvar.h in every c-file. Maybe the linker of this
GNU compiler works not C standard like. No matter. I'll do it like suggested.
Best regards
cs