I have tried the advice on makefile error: undefined reference to main and http://nuclear.mutantstargoat.com/articles/make/. I moved into the directory my makefile was at, ran it and got multiple undefined reference errors.:
My file directory looks like this
makefile
Version3Box (Directory)
SharedCppFiles (Directory)
Box.cpp (#include "Box.h")
SharedHeaders (Directory)
Box.h (#include <SFML/Graphics.hpp>)
Snake (Directory)
CppFiles (Directory)
GridPiece.cpp (#include "Box.cpp", "Box.h", "GridPiece.h")
main.cpp (#include "Box.h", "GridPiece.cpp", "GridPiece.h")
Headers (Directory)
GridPiece.h (#include "Box.h")
And here is my makefile:
# Specify the final target name
EXE := SnakeGame
# Specify the source files
# Effectively list all source files in the current directory
SRC := $(wildcard *.cpp) \
$(wildcard ../*.cpp)
#From the source file list, get the corresponding object file list
OBJ := $(SRC:.cpp=.o)
# From the object file list, get the dependency file list to handle automatic recompilation
# when a header file is modified
DEP := $(OBJ:.o=.d)
# Specify preprocessor flags (This is a built-in variable)
CPPFLAGS := -I../Include
# Required flags to enable the automatic dependency generation by the compiler
CPPFLAGS += -MMD -MP
# Specify compiler flags (This is a built-in variable)
# Basic Warning Flags
CFLAGS := -Wall -W -pedantic
# Specify linker flags (This is a built-in variable)
LDFLAGS := -L../lib -Llib/sfml/lib -lsfml-graphics -lsfml-window -lsfml-system
#Specify linker libraries (This is a built-in variable)
LDLIBS := -lm
# Tell make that these target are not real files
.PHONY: all clean
# Now the standard primary rule
all: $(EXE)
# How do we make $(EXE) ? Remember the recipe describe the linking phase
$(EXE): $(OBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# Let's clean up the mess
clean:
$(RM) $(EXE) $(OBJ) $(DEP)
# Don't forget to include the dependency files to let make know when to recompile
-include $(DEP)
Can someone please help me trouble shoot this code, or generate a different makefile similar to this one? I am trying to learn how to write a better makefile too compared to what I am currently capable of. Thank you so much!
Sorry that I'm adding another undefined reference to main question on SO.