So this is how my defs.h is structured:
#ifndef DEF_H
#define DEF_H
#include <stdio.h>
...
int var = 20;
int test = 1;
...
#endif
Now, I have main.c and util.c, all with:
#include "defs.h"
This is my makefile:
all: clean compile
compile: clean main
@echo SUCCESS: COMPILED FILES
main: main.o util.o
cc main.o util.o -o progname
main.o: main.c
cc -o main.o -c main.c
util.o: util.c
cc -o util.o -c util.c
clean:
-rm -rf *.a *.o *.so progname
@echo SUCCESS: CLEANED FILES
However, when I run make, both object files compile fine, but when doing the final linking I keep getting:
util.o:(.data+0x0): multiple definition of `var'
main.o:(.data+0x0): first defined here
Am I structuring something wrong? Any help would be appreciated.
Thanks