I have three header files ball.h
, wrappers.h
, graphics.h
with corresponding .c
-files. Each .c
file includes its corresponding header file, all of which have include guards. In addition, wrappers.c
includes graphics.h
and wrappers.h
includes ball.h
, which defines a pair of const float
(and more).
In a makefile I have for each of the above pairs an entry of the form
name.o: name.c name.h
with $(CC) -c $^
. Finally, I have a test.c
file (with a main function) which includes each of the above header files, and its makefile entry is test: test.c wrappers.o graphics.o ball.o
with $(CC) $^ -o $@
.
Compiling test
leads to multiple definition error, saying that the aforementioned two const float
are first defined in wrappers.o
and ball.o
.
I suppose this is because wrappers.h
includes ball.h
, but I have no idea how to resolve this, short of moving the offending variables or, worse, changing my code. Is the problem due to awkward includes, or because of the structure of the makefile?
ball.h
excerpt:
#ifndef BALL_H
#define BALL_H
const float circleRadius = 0.025;
const float circleColor = 0;
typedef struct {
float x,y; // etc
} ball_t;
// various function prototypes
#endif /* BALL_H */