Author Topic: Codeblock not finding SDL_image?  (Read 11253 times)

Offline wilbefast

  • Multiple posting newcomer
  • *
  • Posts: 16
Codeblock not finding SDL_image?
« on: September 12, 2009, 05:14:17 pm »
Right, so I'm using a new Ubuntu, a new Codeblocks and I've downloaded and installed libsdl-image1.2 and -dev along with all the other sdl libraries so I can do my SDL tutorial. Everything seemed to be working fine until I was told to start using functions from "SDL_image.h", for example "IMG_Load".

Even though I've included the library (#include <SDL_image.h> or #include <SDL/SDL_image.h> - it makes no difference) I immediately get a:

Code: [Select]
undefined reference to `IMG_Load'
Meanwhile things like SDL_LoadBMP work fine.

Synaptic maintains that the libraries are actually there so clearly I need to manually install something somewhere or rather point Codeblocks in the right direction, I'm just not entirely sure how to go about that.

The code is as follows by the way:

Code: [Select]
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>


void pause();

int main(int argc, char *argv[])
{
    SDL_Surface *screen = NULL, *background = NULL, *zozor = NULL, *pine = NULL;
    SDL_Rect pos_bgrnd, pos_zozor, pos_pine;
            pos_bgrnd.x=0;
            pos_bgrnd.y=0;
            pos_zozor.x=500;
            pos_zozor.y=260;
            pos_pine.x=260;
            pos_pine.y=500;

    SDL_Init(SDL_INIT_VIDEO);

    SDL_WM_SetCaption("SDL Images", NULL);
    SDL_WM_SetIcon(SDL_LoadBMP("sdl_icone.bmp"), NULL);
    screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);


    background = SDL_LoadBMP("lac_en_montagne.bmp");
    SDL_BlitSurface(background, NULL, screen, &pos_bgrnd);


    zozor = SDL_LoadBMP("zozor.bmp");
    SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));
    SDL_SetAlpha(zozor, SDL_SRCALPHA, 150);
    SDL_BlitSurface(zozor, NULL, screen, &pos_zozor);


    pine = IMG_Load("sapin.png");
    SDL_BlitSurface(pine, NULL, screen, &pos_pine);


    SDL_Flip(screen);

    pause();

    SDL_FreeSurface(background);

    SDL_Quit();

    return EXIT_SUCCESS;
}


void pause()
{
    int continue = 1;
    SDL_Event event;

    while (continue)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continue = 0;
        }
    }
}

I'm following a tutorial from http://www.siteduzero.com/ where they use codeblocks, just not codeblocks for Ubuntu it seems (you're only given installation instructions for Mac and Windows)  :?


Any help would be greatly appreciated  :)


William


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12006
    • Travis build status
Re: Codeblock not finding SDL_image?
« Reply #1 on: September 12, 2009, 08:35:44 pm »
You need to used
`sdl-config --cflags` in the additional compiler settings
and
`sdl-config --libs` in the additional linker settings

and another thing:
sdl includes should be with "" not <>

Also search the forum, I guess there is the answer ...
And if you set it up correctly, you can help others in your situation by fixing the tutorial here http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks  :lol: 8)
« Last Edit: September 12, 2009, 08:37:29 pm by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline wilbefast

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Codeblock not finding SDL_image?
« Reply #2 on: September 12, 2009, 09:51:22 pm »
Hmmm...

I managed to figure out a fix, although I was waiting a bit before posting to see if I'd badly messed something else up in the process - the scary thing is it's not the same one as yours  :shock:

I did a system wide search for where Ubuntu had seen fit to put my SDL_image.h file, then copied it into the same directory and linked it manually but it didn't like that very much :-S
Then I fiddled around and eventually went into Project > Build Options > Linker Setting > Add and added my SDL_image file ("/usr/include/SDL/SDL_image.h" without the quotes). It seems to be fairly happy with that though I wouldn't vouch for it since I have really no idea what I'm doing...

William


Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Codeblock not finding SDL_image?
« Reply #3 on: September 12, 2009, 10:38:54 pm »
You should probably read something about how a build-process works.

If you do not know the difference between including header-files and linking libraries, you are missing some absolutely basic knwowledge and are definitely in the wrong forum.


Offline wilbefast

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Codeblock not finding SDL_image?
« Reply #4 on: September 12, 2009, 10:53:37 pm »
Ouch  :?

I guess I'll just dig a very deep hole and jump into it then.

d3mn0id

  • Guest
Re: Codeblock not finding SDL_image?
« Reply #5 on: November 05, 2009, 09:57:21 pm »
What I did was simply to go to Settings->Compiler and debugger->Global compiler settings->Linker settings and add

-lSDL
-lSDL_image

to other linker options

This worked very well, I don't know if it is the best way but hey, it works, only with GNU GCC though.

Offline wilbefast

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Codeblock not finding SDL_image?
« Reply #6 on: November 05, 2009, 10:03:43 pm »
Thought this got locked  :?

That's the fix. It all comes from not knowing the difference between headers and libraries - I'm a bit further on in my studies now, and considerably less ignorant  :)