1

I'm trying to get off the ground with SDL. SDL by itself works fine, I got the basic Hello World setup to work. However, trying to use SDL_image has caused me a ton of headaches. My current code (below) gives me the error 'Img_Load' was not declared in this scope' at line 17.

  • My linker settings in Code::Blocks look like this: "-lmingw32 -lSDLmain -lSDL -lSDL_image"
  • Search directories are properly set up
  • The required DLLs are in the folder with the EXE.

    include iostream
    include fstream
    include "SDL/SDL.h"
    include "SDL_image.h"
    
    using namespace std;
    const int SCREEN_WIDTH = 600;
    const int SCREEN_HEIGHT = 600;
    
    int main(int argc, char *argv[]){
        SDL_Init(SDL_INIT_EVERYTHING);
    
        SDL_Surface* hello = NULL;
        SDL_Surface* screen = NULL;
    
        screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE);
        hello = Img_Load("img\\hello world.png");
    
        if(!hello) //check that the load worked
            cout<<"error";
    
        SDL_BlitSurface(hello, NULL, screen, NULL); //draw image
        SDL_Flip(screen);
    
        SDL_Delay(2000);
    
        SDL_FreeSurface(hello); //closing down
        SDL_Quit();
    
    return 0;
    }
    

Any and all help would be greatly appreciated!

1 Answers1

1

'IMG_Load' confirm case in your source file with the library reference when you reach errors like this.

dans3itz
  • 1,605
  • 14
  • 12
  • Img_Load is the correct case according to the documentation. As well, it gives me a different error if I change the case. The scope error implies the function is defined but just not accessible. – user1586641 Aug 09 '12 at 12:07
  • Oh, not sure then. Hate to add more suggestions without effect, but is SDL_image.a being linked? – dans3itz Aug 09 '12 at 18:34
  • As far as I can tell, SDL_image.lib is being linked (it didn't have a .a file, just a .lib). I've added the -lSDL_image flag to the linker settings, the search directories should see it, and Code::Blocks even gives me code completion suggestions for SDL_image functions. Is there some kind of brute force way to bring stuff into scope in C++? – user1586641 Aug 09 '12 at 22:26