The reason yours fail to compile is that you link the result of compiling Main.cpp together with Main.o. So you link the same file twice.
That's an error on your part where you call the compiler
You probably want something like this
Code:
COMPILER = g++
CCFLAGS = -g
all: myprogram
myprogram: Main.o
${COMPILER} ${CCFLAGS} Main.o -o Main
Main.o:
${COMPILER} ${CCFLAGS} Main.cpp -o Main.o
clean:
rm -rf *.o a.out
I usually just fit any makefiles to the following template:
Code:
SOURCES=Main.cpp file1.cpp file2.cpp file3.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=Main
COMPILER = g++
CCFLAGS = -g
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(COMPILER) $(CCFLAGS) $(OBJECTS) -o $@
.o:
$(COMPILER) $(CCFLAGS) $< -o $@
clean:
rm -f *.o
Bookmarks