I have 3 source files: matrix.c, tetramino.c and learntris.c (which includes the headers tetramino.h
and matrix.h
, linking it with the respective files). I have a structure: struct tetramino
that is need in all these files. After reading this question and its answers- How to use a defined struct from another source file?, I created a header file structure.h
and now my files look like this:
In structure.h:
typedef struct tetramino
{
int type;
char *p;
}tetramino;
In matrix.h:
#include"structure.h"
int print_matrix(void);
int clear_matrix(void);
In tetramino.h:
#include"structure.h"
int rotate(void);
int set_tetramino(void);
And finally, in the main learntris.c file contains:
#include"structure.h"
#include"matrix.h"
#include"tetramino.h"
Now, upon compiling them, I get these errors:
error: redefinition of 'struct tetramino'
and
error: conflicting types for 'tetramino'
Where is the problem?