User forums > Using Code::Blocks
Codeblock not finding SDL_image?
wilbefast:
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: ---undefined reference to `IMG_Load'
--- End code ---
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: ---#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;
}
}
}
--- End code ---
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
oBFusCATed:
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)
wilbefast:
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
Jenna:
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.
wilbefast:
Ouch :?
I guess I'll just dig a very deep hole and jump into it then.
Navigation
[0] Message Index
[#] Next page
Go to full version