Comment comstackr un programme C ++ avec SDL2 sur OS X?

C’est une jolie question de noob. En gros, je n’arrive pas à comstackr un programme Hello World de base sur OSX (Yosemite) à l’aide de la bibliothèque externe SDL2.

J’essaie de faire cela sur console, sans l’aide d’aucun IDE. J’ai déjà installé SDL 2.0.3 et il se trouve sur le chemin /Library/Frameworks/SDL2.framework .

Mon fichier principal ressemble à ceci:

 #include  #include  bool init(); void close(); SDL_Window* gameWindow = NULL; SDL_Surface* gameScreenSurface = NULL; bool init() { ... } void close() { ... } int main( int argc, char** argv) { if( !init() ) { printf( "Failed to initialize!\n" ); } else { SDL_Delay( 2000 ); } close(); return 0; } 

Et j’ai aussi un fichier makefile (tiré d’un exemple que j’ai trouvé quelque part) qui ressemble à ceci:

 CC = g++ LDFLAGS = -g -Wall PROGNAME = doom SOURCES = main.cpp INCLUDES = OBJECTS = $(subst %.cc, %.o, $(SOURCES)) ROOTCFLAGS := $(shell root-config --cflags) ROOTLIBS := $(shell root-config --libs) ROOTGLIBS := $(shell root-config --glibs) ROOTLIBS := $(shell root-config --nonew --libs) CFLAGS += $(ROOTCFLAGS) LIBS += $(ROOTLIBS) all: doom $(PROGNAME): $(OBJECTS) $(CC) $(LDFLAGS) -o doom $(OBJECTS) $(LIBS) %.o : %.cc $(INCLUDES) $(CC) ${CFLAGS} -c -g -o $@ $< 

Et c’est à peu près tout. Lorsque je lance make , je reçois cette réponse:

 make: root-config: Command not found make: root-config: Command not found make: root-config: Command not found make: root-config: Command not found g++ -g -Wall -o doom main.cpp Undefined symbols for architecture x86_64: "_SDL_CreateWindow", referenced from: init() in main-8b6fae.o "_SDL_Delay", referenced from: _main in main-8b6fae.o "_SDL_DestroyWindow", referenced from: close() in main-8b6fae.o "_SDL_GetError", referenced from: init() in main-8b6fae.o "_SDL_GetWindowSurface", referenced from: init() in main-8b6fae.o "_SDL_Init", referenced from: init() in main-8b6fae.o "_SDL_Quit", referenced from: close() in main-8b6fae.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [doom] Error 1 

Alors, puis-je obtenir des conseils s’il vous plaît? Je suis un peu perdu par où commencer. Je n’ai jamais compilé un programme sur OSX ou sur un système d’exploitation basé sur Unix auparavant.

J’ai cherché le truc qui me manque en root-config, et il me semble que je dois installer une bibliothèque appelée Root. Je l’ai fait. Décomprimé sur un répertoire, je ne sais pas où aller à partir de là.

Merci d’avance.

Le fichier Make que vous avez trouvé contient des variables pour le framework d’parsing de données ROOT, et non pour SDL2.

Essayez de courir

 g++ $(sdl2-config --cflags) -g -Wall -o doom main.cpp $(sdl2-config --libs) 

pour commencer.

Comme Amitp l’a dit, vous essayez d’utiliser des indicateurs de compilateur et d’éditeur de liens pour le framework ROOT. Essayez ceci à la place:

 CFLAGS += -F/Library/Frameworks LDFLAGS += -F/Library/Frameworks LIBS += -framework SDL2