Okay, ich mach's mal auf meinem Raspberry Pi vor, da läuft ja auch so was ähnliches wie Debian. Erst mal müssen wir ein paar Sachen installieren:
Code:
sudo apt install libsdl2-2.0 libsdl2-dev build-essential
Da kommen noch ganz viele Abhängigkeiten hinzu, also wundere Dich nicht, wenn es am Ende 50 oder 100 Pakete sind. Als nächstes habe ich das Verzeichnis sdl_hello_world angelegt und darin 2 Dateien gespeichert:
main.cpp
Code:
#include <iostream>
#include <SDL2/SDL.h>
const int WIDTH = 800, HEIGHT = 600;
int main( int argc, char *argv[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Window *window = SDL_CreateWindow( "Hello SDL World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI );
// Check that the window was successfully created
if ( NULL == window )
{
// In the case that the window could not be made...
std::cout << "Could not create window: " << SDL_GetError( ) << std::endl;
return 1;
}
SDL_Event windowEvent;
while ( true )
{
if ( SDL_PollEvent( &windowEvent ) )
{
if ( SDL_QUIT == windowEvent.type )
{
break;
}
}
}
SDL_DestroyWindow( window );
SDL_Quit( );
return EXIT_SUCCESS;
}
Makefile (großes M ist wichtig!)
Code:
# OBJS specifies which files to compile as part of the project
OBJS = main.cpp
# CC specifies which compiler we're using
CC = g++
# COMPILER_FLAGS specifies the additional compilation options we're using
COMPILER_FLAGS = -Wall
# LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lSDL2
# OBJ_NAME specifies the name of our exectuable
OBJ_NAME = main
#This is the target that compiles our executable
all : $(OBJS)
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
Jetzt kannst Du's kompilieren...
...und aufrufen:
Hier ist "./" vor "main" wichtig. Jetzt sollte ein Fenster mit dem Titel "Hello SDL World" erscheinen. Tadaaaaa!
Lesezeichen