Originally Posted by
xshapirox
Does this look any better. It still doesn't work...
Code:
# Makefile for Stack program
all: calc
calc: Stack.o calc.o
g++ stack.o calc.o
Stack.o: Stack.cpp Stack.h
g++ Stack.cpp
calc.o: calc.cpp Stack.h
g++ calc.cpp Stack.cpp
main.o: calc.cpp Stack.h
g++ calc.cpp Stack.cpp -o Calc
I still keep getting undefined reference errors
Something strange I notice, right before the undefined reference error list, there is this:
"g++ Calc.cpp -o Calc"
It should say:
"g++ Stack.cpp Calc.cpp -o Calc"
right?
There seems to be a couple problems. Specificaly with lines
Code:
all: calc
calc: Stack.o calc.o
g++ stack.o calc.o
which have tabs in the dependency headers. Also the label 'calc' doesnt result in the calc executable you want. With the rest of the makefile it seems as though you have an extra label 'main.o' which seems where you attempt to make the real executable but it will never get hit because 'main.o' is never a dependecy of anything. Nor is that the name of the resulting executable so the 'main.o' labal would always run if it could be reached.
The makefile should look something like this:
Code:
# This file should be called makefile
# Makefile for Stack program
# when 'make' gets run it hits the first label then procedes otherwise
# use 'make label' to target a specific label bypassing some dependencies
all: calc
calc: Stack.o calc.o
g++ calc.o Stack.o -o calc
Stack.o: Stack.cpp Stack.h
g++ -c Stack.cpp
calc.o: calc.cpp Stack.h
g++ -c calc.cpp
clean:
rm *.o
rm calc.exe
If calc.cpp is where main is then this should work. The label 'all' could be dropped as 'make' with no targets hits the first label it gets to. Some people always include 'all' for automake stuff because they often generically always target 'all'. The label 'calc' has dependencies on Stack.o and calc.o. Since calc.cpp likely #includes Stack.h and uses the stack object, we have Stack.o first. Once both dependencies have been checked it finally finishes with 'calc'.
It's important to make labels the same as the resulting object or exe file. There must be absolutely no tabs in the 'label: dependencies' line. Make sure all dependencies have valid labels.
I believe if your still having trouble this should help you.