Hello everyone! So i have this issue : i am declaring some extern global variables in my C program. If I don't use the -c option for gcc, i get undefined references errors. But with that -c option, the linking is not done, which means that i don't have an executable generated.
So how do I solve this?
Here is my makefile (written thanks to Alex)
CC = gcc # compiler/linker frontend
INCL = -I$(INCL_DIR) # includes
DEFS = -D_DEBUG_ # defines
CFLAGS = -g $(INCL) $(DEFS) # compiler flags
LFLAGS = -lpthread -lm -g # linker flags
OBJ = approx.o producteur.o sequentialApproximation.o main.o
BIN = calculPi.exe
LINKOBJ = approx.o producteur.o sequentialApproximation.o main.o
RM = rm -fv
all: $(BIN)
clean:
${RM} *\~ \#*\# $(OBJ)
clean_all: clean
${RM} $(BIN)
cleanall: clean
${RM} $(BIN)
$(BIN): $(OBJ)
$(CC) $(LFLAGS) -o $@ $^
main.o: main.c
approx.o: approx.c approx.h
producteur.o: producteur.c producteur.h
sequentialApproximation.o : sequentialApproximation.c sequentialApproximation.h
.c.o:
$(CC) $(CFLAGS) -c $<
And here is the output of make : http://pastebin.com/NzsFetrn
I did declare extern variables in approx.h (extern and global) and i try to call them in approx.c, and there it doesn't work.