I’m still getting use to setting up Makefiles and using SDL both, and I’m having trouble getting the makefile to work correctly. I don’t know if it’s a problem with my makefile or if I’m doing something wrong with SDL. Here is my make file:
#Game Make file
EXEC = game.exe
OBJS = App.o\
App_OnInit.o\
App_OnEvent.o\
App_OnLoop.o\
App_OnRender.o \
App_OnCleanup.o
CC = g++
CFLAGS = -o $(shell sdl-config --cflags)
LIBS =
LDFLAGS = $(shell sdl-config --libs)
$(EXEC): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $@ $(OBJS) $(LIBS)
%.o: src/%.cpp
$(CC) -c $<
.PHONY: clean
clean:
rm -f $(EXEC) $(OBJS) *~
When I try and make it though I get this:
g++ -c src/App.cpp
g++ -c src/App_OnInit.cpp
g++ -c src/App_OnEvent.cpp
g++ -c src/App_OnLoop.cpp
g++ -c src/App_OnRender.cpp
g++ -c src/App_OnCleanup.cpp
g++ -o -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -L/usr/lib/i386-linux-gnu -lSDL game.exe App.o App_OnInit.o App_OnEvent.o App_OnLoop.o App_OnRender.o App_OnCleanup.o
g++: error: game.exe: No such file or directory
make: *** [game.exe] Error 1
I’m trying to piece together how to use makefiles correctly, but most every site I find on them show you a completely different way of using them and it’s making it hard to learn them.
It’s a problem with the makefile. When it gets to this bit:
the -o option sets the name of the output file. You want to have something more like:
I’m not too hot on Makefiles but my guess would be to have something like this:
and change CFLAGS to not include the -o option:
I think it would probably also help to learn how to build it manually (ie, using g++ from the command line yourself) before trying to automate the process.