SDL Programm funktioniert nicht
-
moin
ich bitte alle mods dieses Forums dieses thema solange nicht ins Grafikprogrammierung-Forum zu verschieben, bis ich eine Lösung für mein Problem hab.
ich hab das Hello World Programm von SDL:
#include "SDL/SDL.h" #include <string> //The attributes of the screen const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; //The surfaces that will be used SDL_Surface *message = NULL; SDL_Surface *background = NULL; SDL_Surface *screen = NULL; SDL_Surface *load_image( std::string filename ) { //Temporary storage for the image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = SDL_LoadBMP( filename.c_str() ); //If nothing went wrong in loading the image if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; } void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Make a temporary rectangle to hold the offsets SDL_Rect offset; //Give the offsets to the rectangle offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset ); } int main( int argc, char* args[] ) { //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 1; } //Set up the screen screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); //If there was an error in setting up the screen if( screen == NULL ) { return 1; } //Set the window caption SDL_WM_SetCaption( "Hello World", NULL ); //Load the images message = load_image( "hello_world.bmp" ); background = load_image( "background.bmp" ); //Apply the background to the screen apply_surface( 0, 0, background, screen ); //Apply the message to the screen apply_surface( 250, 140, message, screen ); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Wait 2 seconds SDL_Delay( 2000 ); //Free the surfaces SDL_FreeSurface( message ); SDL_FreeSurface( background ); //Quit SDL SDL_Quit(); //Return return 0; }
.. wenn ich es in Visual C++ Express kompiliere, kommt genau das was ich will.
Aber wenn ich in den DEBUG-Ordner meines Projektverzeichnis gehe und die Anwendung ausführe, kommt nur ein Fenster mit schwarzem Hintergrundkann mir jemand bitte helfen?
Liebe Grüße
Roland Render
-
Wie wäre es, wenn du mal eine Fehlerbehandlung einbaust? Zum Beispiel für den Fall, dass die Bitmapdateien nicht da sind, wo du sie erwartest.
-
Verhält sich das Programm auch so wenn du es als Release Version kompilierst?
-
phlox81 schrieb:
Verhält sich das Programm auch so wenn du es als Release Version kompilierst?
hi
danke für die Antwort
also Release funktioniert bei mir überhaupt nicht
wenn ich bei der konfiguration auf "Release" stelle, dann in den Projekteigenschaften bei codegenerierung auf Multithreaded (/MT) klicke(also dass es statisch gelinkt wird,dass man keine Dateien mitgeben muss, um es auf anderen PC's ausführen zu müssen), und anschließend kompiliere:1>------ Erstellen gestartet: Projekt: SDL_Program, Konfiguration: Release Win32 ------ 1>Kompilieren... 1>main.cpp 1>Verknüpfen... 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_WM_SetCaption". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_Flip". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_RWFromFile". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_Delay". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_Init". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_LoadBMP_RW". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_DisplayFormat". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_SetVideoMode". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_UpperBlit". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_Quit". 1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_SDL_FreeSurface". 1>LIBCMT.lib(crt0.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "_main". 1>C:\Users\Roland Render\Desktop\Projekte\test\Release\test.exe : fatal error LNK1120: 12 nicht aufgelöste externe Verweise. 1>Das Buildprotokoll wurde unter "file://c:\Users\Roland Render\Desktop\Projekte\test\test\Release\BuildLog.htm" gespeichert. 1>test - 13 Fehler, 0 Warnung(en) ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
freue mich über antworten
Liebe Grüße
Roland Render
-
Da ist wohl eine Library vergessen worden dazu zu linken, schau mal ob du für Release auch die SDL Libs dazu linkst.
-
phlox81 schrieb:
Da ist wohl eine Library vergessen worden dazu zu linken, schau mal ob du für Release auch die SDL Libs dazu linkst.
Ja, danke, aber das Problem ist nun,dass ich nicht weiß, wo ich das in Vc++ finde und was ich da einstellen muss
Diese Anleitung habe ich genommen:
http://lazyfoo.net/SDL_tutorials/lesson01/windows/msvsnet05e/index.php
-
Hallo
Bei den Projektoptionen wählst du Linker aus und dort INput. Dort trägst du die benötigten libs ein. Ich bevorzuge aber folgendes:
#pragma comment(lib, "sdl.lib") #pragma comment(lib, "sdlmain.lib")
chrische
-
chrische5 schrieb:
Hallo
Bei den Projektoptionen wählst du Linker aus und dort INput. Dort trägst du die benötigten libs ein. Ich bevorzuge aber folgendes:
#pragma comment(lib, "sdl.lib") #pragma comment(lib, "sdlmain.lib")
chrische
hab ja SDL.lib SDLmain.lib hineingeschrieben unter "Eingabe" in "Linker".
Trodzdem kommt die gleiche Meldung :S
-
Hallo
Hast du mal die 2. Methode probiert. das gehört dann natürlich in den Quellcode.
chrische
-
chrische5 schrieb:
Hallo
Hast du mal die 2. Methode probiert. das gehört dann natürlich in den Quellcode.
chrische
1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) ist bereits in LIBCMT.lib(typinfo.obj) definiert. 1>msvcrt.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) ist bereits in LIBCMT.lib(typinfo.obj) definiert. 1>msvcrt.lib(MSVCR80.dll) : error LNK2005: _isspace ist bereits in LIBCMT.lib(_ctype.obj) definiert. 1>msvcrt.lib(MSVCR80.dll) : error LNK2005: _exit ist bereits in LIBCMT.lib(crt0dat.obj) definiert. 1>LIBCMT.lib(crt0init.obj) : warning LNK4098: Standardbibliothek "msvcrt.lib" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Bibliothek verwenden. 1>C:\Users\Roland Render\Desktop\Projekte\test\Release\test.exe : fatal error LNK1169: Mindestens ein mehrfach definiertes Symbol gefunden.
kommt beim compilieren dann mit pragma ..
-
Sorry für Push aber waren das zu wenig infos, dass ihr nicht antwortet?
Liebe Grüße
Roland Render