I'm learning using the SDL librarie, with a french site. This is the tuto :
"There may be some of you who have gotten into the habit of compiling by hand under Linux using a Makefile (file controlling compilation). If this is your case, I invite you to download a Makefile which you can use to compile SDL projects.
The only thing a little special is the addition of the SDL library for the linker (LDFLAGS). You will have to download the Linux version of the SDL and install it in your compiler folder"
I've found my gcc folder in /usr/bin/gcc , but when I want to move the makefile to this folder, the error is :
mv: cannot move 'makefile_sdl' to '../usr/bin/makefile_sdl': Permission denied
There it is my make file, maybe something's wrong or missing (i'm a beginner ahah)
CPP=gcc #compiler command
CFLAGS=-O3 #Option d'optimisation du programme
LDFLAGS=-lSDL -lSDL_mixer #Linker
EXEC=nomProgramme #Nom du programme à modifier
all: ${EXEC}
${EXEC}: ${EXEC}.o
${CPP} $(CFLAGS) -o ${EXEC} ${EXEC}.o ${LDFLAGS}
${EXEC}.o: ${EXEC}.c
${CPP} $(CFLAGS) -o ${EXEC}.o -c ${EXEC}.c
You need to name your Makefile Makefile
. Case sensitive, make sure to check for spelling errors, etc. You also need to be in the same directory as Makefile
when you run make
.
You should also just run make
without any specified targets. It will automatically build the all
target, which will build your program into an executable called nomProgramme
.
You'll also need to install libsdl-mixer1.2-dev
(sudo apt-get install libsdl-mixer1.2-dev
and change EXEC=main
back to EXEC=nomProgramme
.
Here's a link to the GNU make
documentation. It gives a quick overview and then a very detailed explanation of everything you can do with GNU make
: https://www.gnu.org/software/make/manual/make.html