This sucks...SDL
Have you tried using this in an SDL project? Its one of the options when you make a new project in Dev C++(assuming that you installed SDL via a DevPak).
Try the following:
1) For the header, use: (reason: http://www.libsdl.org/faq.php?action=listentries&category=2#19 )
2) Make sure sure in dev-c++ when you make a new project, choose console.
3) Link with:
4) Did you download the header and lib files for SDL? Make sure you place them in dev-c++'s include and lib directories, else you'll have to add include directories in options.
5) You can place the SDL.dll in the programs working directory, or c:/windows/system32 Even if you don't have the dll, I think it should compile, but give an error when you try to run it.
6) As mentioned, if you use a path either escape the slashes, or use foreward slashes.
If dev-c++ is installed correctly, and you link with the above, this code should compile. (I just tested it, basically a sdl-hi world)If that still doesn't work, post all errors.
1) For the header, use: (reason: http://www.libsdl.org/faq.php?action=listentries&category=2#19 )
#include "SDL.h"
2) Make sure sure in dev-c++ when you make a new project, choose console.
3) Link with:
-lmingw32 -lSDLmain -lSDL -mwindows
4) Did you download the header and lib files for SDL? Make sure you place them in dev-c++'s include and lib directories, else you'll have to add include directories in options.
5) You can place the SDL.dll in the programs working directory, or c:/windows/system32 Even if you don't have the dll, I think it should compile, but give an error when you try to run it.
6) As mentioned, if you use a path either escape the slashes, or use foreward slashes.
background = load_image( "C:\Dev-CPP\lessson02\background.bmp" );//becomes:background = load_image( "C:\\Dev-CPP\\lessson02\\background.bmp" );//or: (Pretty sure I've used foreward slashes in windowsbackground = load_image( "C:/Dev-CPP/lessson02/background.bmp" );
If dev-c++ is installed correctly, and you link with the above, this code should compile. (I just tested it, basically a sdl-hi world)
#include <iostream>//#include <cstdlib> //if you need to pause#include "SDL.h"using namespace std;int screen_w = 800;int screen_h = 600;int screen_bpp = 32; //32 works -- 16?//push escape to quit.//compiling: linked with: -lmingw32 -lSDLmain -lSDL -mwindowsbool bDone = false;//proto'svoid game_loop(void);//surfacesSDL_Surface *screen;void game_loop(void) { //render blank screen //init before loop SDL_Event event; Uint8 *keys; cout << "Starting render loop" << endl; //loop do { //events while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { //nice quit bDone = true; } } //input keys = SDL_GetKeyState(0); if(keys[SDLK_ESCAPE] == SDL_PRESSED) { bDone = true; } //render SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format,0,128,128)); SDL_UpdateRect(screen,0,0,0,0); }while(!bDone); cout << "Exited render loop" << endl;}int main(int argc, char *argv[]) { //init before loop //init SDL if(SDL_Init(SDL_INIT_VIDEO) < 0) { cerr << "Could not initialize SDL: " << SDL_GetError() << endl; SDL_Quit(); return -1; } //set video mode screen = SDL_SetVideoMode(screen_w, screen_h, screen_bpp, SDL_SWSURFACE); if(screen == NULL) { cerr << "Failed setting mode: " << screen_w << "x" << screen_h << "x" << screen_bpp << endl << SDL_GetError() << endl; SDL_Quit(); return -1; } game_loop(); //end SDL //free surfaces, but not screen cout << "Quitting SDL..." << endl; SDL_Quit(); cout << "Done." << endl; return 0;}
hey,
sorry your having such a difficult time with this.
i know it was a pain to get SDL up and running on my Dev C++ when i first started. I got this error a lot and it was always due to libraries.
i would check the order in which you have linked your libraries.
i read once that you need to have libSDLmain.lib first, foremost, and before all the others. if i wasnt at work, id check myself to see if this is valid, but unfortunatly all i can do is blindly poke at the problem.
good luck!
sorry your having such a difficult time with this.
i know it was a pain to get SDL up and running on my Dev C++ when i first started. I got this error a lot and it was always due to libraries.
i would check the order in which you have linked your libraries.
i read once that you need to have libSDLmain.lib first, foremost, and before all the others. if i wasnt at work, id check myself to see if this is valid, but unfortunatly all i can do is blindly poke at the problem.
good luck!
The proper way to include is <SDL/SDL.h> not "SDL.h" or anything else. Just wanted to clear this one.
Quote:Original post by Feidias
The proper way to include is <SDL/SDL.h> not "SDL.h" or anything else. Just wanted to clear this one.
So do I [smile]
The correct way, according to the SDL webpage, is actaully "SDL.h".
Then, (for dev-cpp), go into tools->compiler options->directories->c (and c++) includes and add your SDL include directory to it, so on mine in both c and c++ includes it reads "C:\path\to\Dev-Cpp\include\SDL"
Quote:Original post by Feidias
The proper way to include is <SDL/SDL.h> not "SDL.h" or anything else. Just wanted to clear this one.
Incorrect. just wanted to make it clear :)
Quote:Original post by Feidias
The proper way to include is <SDL/SDL.h> not "SDL.h" or anything else. Just wanted to clear this one.
No, it's <#SDL.//h-#>
Seriously, it completely depends on what your include directories are set as. That's why everyone's is different... there is no "correct" way.
Your include directory should be set to "include" directory of the compiler. Then when you write for example include <stdio.h> it's found from the include directory. Using "myheader.h" suggests that the file is located in the project directory, where your source files are.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement