How to install/compile SDL2 C code on Linux/Ubuntu -
i'm doing c programming , want use sdl library. want build small 2d game in c on linux sharp skills bit.
my issue i'm not super makefile user nor library on linux super user, configure things once when on project , that's it.
so have trouble compiling sdl2 programs on ubuntu 14.04.
i downloaded latest sdl library : http://www.libsdl.org/download-2.0.php
then installed default step:
./configure make sudo make install
after can see there in /usr/include/sdl2 guess installed.
#include <stdlib.h> #include <stdio.h> #include <sdl2/sdl.h> int main(int argc, char *argv[]) { printf(“sdl test\n”); return 0; }
because i'm still learning makefiles , sdl didn't figure out make it.
but found makefile compile old sdl not sdl2
cpp=gcc cflags=-o3 ldflags=-lsdl -lsdl_mixer #linker exec=test all: ${exec} ${exec}: ${exec}.o ${cpp} $(cflags) -o ${exec} ${exec}.o ${ldflags} ${exec}.o: ${exec}.c ${cpp} $(cflags) -o ${exec}.o -c ${exec}.c clean: rm -fr *.o mrproper: clean rm -fr ${exec}
but makefile not working me says doesn't know lsdl_mixer , other stuff.
how can build workable makefile compile c program sdl2 using makefiles , vim editor.
thanks in advance help
i'll go ahead , clean makefile you.
cflags = -o3 ldflags = appname = test all: $(appname) clean: rm -f $(appname) *.o .phony: clean sdl_cflags := $(shell pkg-config --cflags sdl2 sdl2_mixer) sdl_libs := $(shell pkg-config --libs sdl2 sdl2_mixer) override cflags += $(sdl_cflags) override libs += $(sdl_libs) $(appname): test.o $(cc) $(ldflags) -o $@ $^ $(libs)
explanation
variables in makefile should used
$(...)
, not${...}
.pkg-config
has entry sdl_mixer,sdl-config
not.pkg-config
more general.using
override
sdl flags allows runmake cflags="-o0 -g"
without breaking sdl support.this important: sdl library flags have @ end of command line, in
libs
, due fact gnu linker sensitive order in libraries specified.you don't need explicit rules
.c
files, because gnu make has implicit rules fine.
note there important features missing makefile. example, won't automatically recompile things when change header files. recommend use build system, such cmake or scons, handles automatically. can make, you'd have paste several arcane lines of code makefile.
Comments
Post a Comment