Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
SDL kompilieren [gelöst]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
oliver2104
Apprentice
Apprentice


Joined: 27 Jul 2004
Posts: 214
Location: Wien

PostPosted: Sun Mar 22, 2015 10:25 am    Post subject: SDL kompilieren [gelöst] Reply with quote

Hallo,
beschäftige mich gerade mit den ersten Schritten zur SDL-Programmierung.
in allen Tutorials wird zum kompilieren folgendes Kommando empfohlen:
Code:

gcc datei.c -o datei `sdl-config --cflags --libs`

das funktioniert auch, aber was bedeutet `sdl-config --cflags --libs`
kenne bis jetzt eigentlich nur die kompileroptionen in der Form -lSDL usw.
und wie kann ich `sdl-config --cflags --libs` in ein Makefile integrieren ?
dh. wie muß LDFLAGS aussehen ?

bitte um Hilfe


Last edited by oliver2104 on Fri Mar 27, 2015 11:51 am; edited 1 time in total
Back to top
View user's profile Send private message
mrsteven
Veteran
Veteran


Joined: 04 Jul 2003
Posts: 1938

PostPosted: Sun Mar 22, 2015 1:35 pm    Post subject: Re: SDL kompilieren Reply with quote

oliver2104 wrote:
das funktioniert auch, aber was bedeutet `sdl-config --cflags --libs`

Das bedeutet: "Nimm das, was das Kommando in den Akzentzeichen auf der Standardausgabe ausgibt und schreibe es an diese Stelle hin."
Auf meinem Rechner gibt sdl-config --cflags --libs das hier aus:
Code:
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
-lSDL -lpthread

Das heißt, dein Kommando wird zu dem hier:
Code:

gcc datei.c -o datei -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT \
-lSDL -lpthread

Das wird auch als Kommandosubstitution bezeichnet.

Quote:
kenne bis jetzt eigentlich nur die kompileroptionen in der Form -lSDL usw.
und wie kann ich `sdl-config --cflags --libs` in ein Makefile integrieren ?
dh. wie muß LDFLAGS aussehen ?

Im Prinzip kannst du das so machen wie auf der Shell auch, nur dass du eben z.B. für die LDFLAGS nur die Ausgabe von sdl-config --libs nimmst:
Makefile:
LIBS = -lirgendeineanderelibrary `sdl-config --libs`
# ...
my_program: my_program.o
    gcc my_program.o -o my_program $(LIBS)

Make ersetzt dann $(LIBS) durch -lirgendeineanderelibrary `sdl-config --libs`. Die Shell ersetzt anschließend das sdl-config-Kommando durch seine Ausgabe.

PS: Im Makefile natürlich Tabs statt Spaces für die Kommandos zum Bauen verwenden!
_________________
Unix philosophy: "Do one thing and do it well."
systemd: "Do everything and do it wrong."
Back to top
View user's profile Send private message
oliver2104
Apprentice
Apprentice


Joined: 27 Jul 2004
Posts: 214
Location: Wien

PostPosted: Tue Mar 24, 2015 11:38 am    Post subject: Reply with quote

Danke für deine sehr hilfreiche Antwort,
auch auf meinem Rechner ergibt sdl-config --cflags --libs
Code:
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -lSDL -lpthread

kann das jetzt explizit ins Makefile schreiben
und alles funktioniert.
Code:
#Makefile
LDFLAGS = -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -lSDL -lpthread   
# ...
my_program: my_program.c
    gcc my_program.c -o my_program $(LDFLAGS)

aber das mit der automatischen Auflösung hab ich noch nicht verstanden
Code:
#Makefile
LIBS = -lirgendeineanderelibrary `sdl-config --libs`
# ...
my_program: my_program.c
    gcc my_program.c -o my_program $(LIBS)

funktioniert so bei mir nicht
Back to top
View user's profile Send private message
Christian99
Veteran
Veteran


Joined: 28 May 2009
Posts: 1668

PostPosted: Tue Mar 24, 2015 12:27 pm    Post subject: Reply with quote

vermutlich weil du keine libirgendeineanderelibrary.so hast :)
das solltest du natürlich noch entfernen oder durch eine Bibliothek ersetzen mit der du auch noch linken willst.

zur kommandosubstitution lies doch am besten mal hier: http://www.linux-praxis.de/linux1/shell1_7.html
(oder eine der millionen anderen Seiten, die google zu diesem thema ausspuckt)
Back to top
View user's profile Send private message
oliver2104
Apprentice
Apprentice


Joined: 27 Jul 2004
Posts: 214
Location: Wien

PostPosted: Thu Mar 26, 2015 9:20 am    Post subject: Reply with quote

Quote:
vermutlich weil du keine libirgendeineanderelibrary.so hast

richtig vermutet, hab das entfernt und jetzt gehts.
nochmals Danke.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum