I'm getting these errors with the following
foo.h
:
#ifndef __FOO_H__
#define __FOO_H__
unsigned char some_array[32];
unsigned char some_variable = 0;
void some_function(void);
#endif
foo.c
:
void some_function(void)
{
// Code using some_array and some_variable
}
However, if I were to instead do
foo.h
:
#ifndef __FOO_H__
#define __FOO_H__
void some_function(void);
#endif
foo.c
unsigned char some_array[32];
unsigned char some_variable = 0;
void some_function(void)
{
// some code using some_array and some_variable
}
then it compiles with no errors. What's going on here?
Solution
The solution turned out to be to add extern
to the header definitions of the variables, and to redefine them in the c file, although, I am unsure as to why this worked.
foo.h
#ifndef __FOO_H__
#define __FOO_H__
extern unsigned char some_array[32];
extern unsigned char some_variable;
void some_function(void);
#endif
foo.c
:
unsigned char some_array[32];
unsigned char some_variable = 0;