Viele Fehler bei Kompilierung von C++/SDL mit CodeBlocks (MinGW) [Gelöst]
-
Ich habe das SDL-Paket heruntergeladen und extrahiert. Nun erstelle ich mit dem Assistent von CodeBlocks ein SDL Projekt. Das ist der Standard Code der dabei erstellt wird:
//main.cpp #ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #ifdef __APPLE__ #include <SDL/SDL.h> #else #include <SDL.h> #endif int main ( int argc, char** argv ) { // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE|SDL_DOUBLEBUF); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } // load an image SDL_Surface* bmp = SDL_LoadBMP("cb.bmp"); if (!bmp) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; } // centre the bitmap on screen SDL_Rect dstrect; dstrect.x = (screen->w - bmp->w) / 2; dstrect.y = (screen->h - bmp->h) / 2; // program main loop bool done = false; while (!done) { // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) done = true; break; } } // end switch } // end of message processing // DRAWING STARTS HERE // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); // draw bitmap SDL_BlitSurface(bmp, 0, screen, &dstrect); // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(screen); } // end main loop // free loaded bitmap SDL_FreeSurface(bmp); // all is well ;) printf("Exited cleanly\n"); return 0; }Doch wenn ich das ganze jetzt kompilieren will, hagelt es Fehlermeldungen.
||=== Test, Debug ===| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_main.h|26|SDL_stdinc.h: No such file or directory| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_main.h|67|error: `Uint32' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_main.h|67|error: ISO C++ forbids declaration of `style' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_endian.h|60|error: `Uint16' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_endian.h|93|error: `Uint32' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|31|SDL_mutex.h: No such file or directory| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|32|SDL_thread.h: No such file or directory| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|33|SDL_rwops.h: No such file or directory| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|44|error: `Uint16' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|45|error: `Uint8' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|46|error: `Uint8' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|47|error: `Uint16' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|48|error: `Uint16' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|49|error: `Uint32' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|56|error: `Uint8' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|56|error: ISO C++ forbids declaration of `stream' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|83|error: `Uint16' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|84|error: `Uint16' does not name a type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|86|error: ISO C++ forbids declaration of `Uint8' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|86|error: expected `;' before '*' token| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|91|error: `Uint16' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|91|error: ISO C++ forbids declaration of `format' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|warning: `SDL_LoadWAV_RW' initialized and declared `extern'| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `SDL_RWops' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `src' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: expected primary-expression before "int"| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: expected primary-expression before '*' token| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `spec' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `Uint8' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `audio_buf' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `Uint32' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: `audio_len' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|190|error: initializer expression list treated as compound expression| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|199|warning: `SDL_FreeWAV' initialized and declared `extern'| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|199|error: variable or field `SDL_FreeWAV' declared void| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|199|error: `Uint8' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|199|error: `audio_buf' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|209|error: `Uint16' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|209|error: `Uint8' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|210|error: `Uint16' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|210|error: `Uint8' has not been declared| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|210|error: ISO C++ forbids declaration of `src_format' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|210|error: ISO C++ forbids declaration of `src_channels' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|210|error: ISO C++ forbids declaration of `dst_format' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|210|error: ISO C++ forbids declaration of `dst_channels' with no type| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|warning: `SDL_MixAudio' initialized and declared `extern'| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: variable or field `SDL_MixAudio' declared void| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: `Uint8' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: `dst' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: expected primary-expression before "const"| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: `Uint32' was not declared in this scope| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: expected primary-expression before "int"| C:\SourceCode\Libraries\SDL-1.2.13\include\SDL_audio.h|230|error: initializer expression list treated as compound expression| ||More errors follow but not being shown.| ||Edit the max errors limit in compiler options...| ||=== Build finished: 50 errors, 3 warnings ===|Weiß einer, was zu tun ist? Vielen Dank vorab!
-
stimmt zufällig was mit deiner SDL-installation nicht? Oder sind die Umgebungsvariablen nicht korrekt gesetzt? Die zu inkludierenden Dateien werden nämlich nicht gefunden.
-
Die Installation besteht doch eigentlich nur aus dem Entpacken des Archivs in einen Ordner. Das habe ich getan. Umgebungsvariablen habe ich nicht gesetzt. Bei CodeBlocks gibt man ja in den Projekteinstellungen den Pfad zu SDL an, dann scheint CB auf Umgebungsvariablen zu verzichten. Ich habe jetzt trotzdem mal testweise den SDL-Pfad in Path gesetzt. Ohne Erfolg.
Muss denn das ganze doch irgendwie anders installiert werden, oder muss ich eine andere Umgebungsvariable setzen?
-
Hast du auch wirklich alle Include-Verzeichnisse (und auch andere benötigte Verzeichnisse, z.B. Bibliotheken) bei den Optionen der Entwicklungsumgebung hinzugefügt? Und stimmen die Pfade?
-
Normalerweise sucht sich Code::Blocks das doch selbst?! Wie aufgefordert, habe ich in dem SDL-Projekt-Assisteneten den Pfad zu SDL angegeben.
-
Ich habe Code::Blocks jetzt komplett entfernt und nochmal neu installiert. Nun habe ich bei den Projekteinstellungen nicht den Pfad sondern die vorgeschlagene Benutzervariable angegeben. Diese kann dann in CB definiert werden (mit include-, lib- etc. Ordner). Und nun funktionierts. Einwandfrei.