gcc does not resolve extern global variables, with or without -c option

Posted by Moons on Stack Overflow See other posts from Stack Overflow or by Moons
Published on 2010-05-08T10:07:16Z Indexed on 2010/05/08 10:28 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|

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. As I am not good with writing makefiles, I took one from another project then I changed a few things. So maybe I'm missing something here.

# Makefile calculPi

INCL = -I$(INCL_DIR)
DEFS = -D_DEBUG_

CXX_FLAGS =-g -c -lpthread -lm
CXX = gcc $(CXX_FLAGS) $(INCL) $(DEFS)

LINK_CXX = gcc

OBJ  = approx.o producteur.o sequentialApproximation.o main.o
LINKOBJ  = approx.o producteur.o sequentialApproximation.o main.o
BIN  = calculPi.exe
RM = rm -fv

all:  calculPi.exe

clean:
    ${RM} *\~ \#*\# $(OBJ)

clean_all: clean
    ${RM} $(BIN)

cleanall: clean
    ${RM} $(BIN)

$(BIN): $(OBJ)
    $(CXX) $(LINKOBJ) -o "calculPi.exe"

main.o: main.c
    $(CXX) main.c -o main.o $(CXX_FLAGS)

approx.o: approx.c approx.h
    $(CXX) -c approx.c -o approx.o $(CXX_FLAGS);

producteur.o: producteur.c producteur.h
    $(CXX) -c producteur.c -o producteur.o $(CXX_FLAGS);

sequentialApproximation.o : sequentialApproximation.c sequentialApproximation.h
    $(CXX) -c sequentialApproximation.c -o sequentialApproximation.o $(CXX_FLAGS);

© Stack Overflow or respective owner

Related posts about c

    Related posts about linker