SDL_image + linking issues

Nibbie
Posts: 3
Joined: 2005.07
Post: #1
Hello Everyone,

I have been using SDL for cross-platform development for a while now, but I just decided to use SDL_image a few days ago and I have a lot of trouble getting it to link with my program.

I use SDL 1.2.8 and I installed SDL_image using the most recent "package" installer from the SDL website.

The frameworks for these reside in /Library/Frameworks.

The project I am trying to compile is an Xcode SDL-templated project. When I include the framework in the project, and include the header in my source file (#include <SDL_image/SDL_image.h>), I get the following link error:

Quote: ProjectName 1.3:0: Undefined symbols: _SDL_Error referenced from @executable_path/../Frameworks/SDL_image.framework/Versions/A/SDL_image expected to be defined in SDL

I am not great at understanding compiler errors, but "Undefined symbols" tells me that the compiler cannot find a framework or source file. The "@executable_path" must mean it is looking in my app bundle, but I don't know what I need to do to make it happy. I have set search paths to /Library/Frameworks/SDL_image.framework/Headers, and still no luck.

Would someone mind helping me out here? I hope I have provided enough information to yield some advice because I'm really stuck.

I have found a couple of threads on idevgames that are similar to my problem, but I have yet to find a solution.

Thanks for taking the time to read this. I appreciate it!


---
Dard.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
Im having the same problem, using -I/Library/Frameworks/SDL_image.framework/Headers didnt do it,

I then tried installing SDL_image, from source so i had to install libpng-1.2.8 and jpeg-6b, then putting -lSDL_image in the gcc line sorted the Undefined symbols.

So that was good,

but then tex = IMG_Load("myImage.jpg");
doesnt load the image, it just gives me tex = null

HELP someone?????
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Can i just ask actually, has anyone got SDL_image working and loading images and stuff on mac os x (and what version)?
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #4
I've had it working on all versions of 10.3.x.

To include it, just add it to your project like normal. Then create a new copy files build phase. In the targets area, move the copy files phase to the top (not sure if it's necessary but always was for me). Set the location of the copy files phase to Frameworks. Then just add any frameworks that are not standard into it (SDL, and SDL_image). Then just make sure you also have the frameworks in the normal frameworks build phase. The targets area should look like this:
[Image: targets.jpg]

If that's what you have (and you set the copy files build phase to copy into frameworks) you'll be all set.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
Im not using xcode, just makefiles so its a bit harder Wacko
Ive got it included ok, it just doesnt load images
when i do

Code:
SDL_Surface* myTexture = IMG_Load("myTexture.jpg");

myTexture remains null and if i try to use it the application crashes.
Am i using IMG_Load wrong or should i use somthing else?
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #6
Is myTexture.jpg an actual file that's in the same folder as the app? That's where it's going to try and get files from usually. Another thing (won't help it staying null) but usually you need to SDL_LockSurface(myTexture); before you can do anything with the surface. I'm sure there are exceptions but i've yet to find one.

One little thing though (won't fix the problem but will help with crashes) would be to use error checking like this:
Code:
SDL_Surface *aSurface;
if((aSurface = IMG_Load("myTexture.jpg")) == NULL)
{
printf("Failed to load myTexture");
//then just quit or return false or whatever you need to do
}
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
The image is in the same folder as the application.
It just isnt loading the image I always get myTexture == null.
Ive added SDL_LockSurface(tex); after the bit where I quit when I get a null image.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2005.07
Post: #8
Thanks for the info, Nick. Unfortunately I still turn up the exact same error. I created a copy build phase like the one you showed and I checked the app contents. The two frameworks are copied there like they are supposed to.

The only code I have in my app that utilizes SDL_image is:
Code:
SDL_Surface* img_data = IMG_Load(filename);

if (img_data == NULL){
    fprintf(stderr, "IMG_Load: %s\n", IMG_GetError());
    exit(1);
}

If I remove it, then the compiler gives me no error.

Are there any other compiler settings that could possibly need adjusting?

Thanks again!


---
Dard.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #9
I'm not sure. Maybe the fprintf() line has something nasty in it. I'm not sure though. I've never really used built in errors (like IMG_GetError()). What happens if you use something like this for the error checking:
Code:
if(img_data == NULL)
{
        printf("failed to load.");
        exit(1);
}
I don't know if that's it or not. That's definitely unusual. I'll see if there's anything else in my project (it uses SDL and SDL_image) that might be of some use.

Have you tried cleaning the target and building from scratch? Sometimes that can actually help. Also try turning off Zerolink. Not sure that'll actually help but still worth a quick try.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2005.07
Post: #10
I just made a new project using the Xcode opengl-sdl template. I added the frameworks (SDL.framework and SDL_image.framework), as well as the copy phase. I then inserted this line of code (in addition to including the headers):

Code:
SDL_Surface* img_data = IMG_Load("hello");

I got the same error, unfortunately. So I know it's not the error reporting that is messing it up. Could it be that SDL_image.framework just isn't going to work on my computer?

I guess I'll just have to find something else that does the job, at least until I can figure out how to get around this annoying error. Annoyed


---
Dard.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #11
yeah, i managed to build jpeglib zlib pnglib then SDL_image and showimage worked with a gif, but jpg and png files give a "unsupported graphic file" error.

Anyone got hints on compiling SDL_image from source?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #12
Huh?
If I change it to load a bmp file it works, but jpg and png are unsupported and gif doesnt turn into a texture properly.
Anyone know why or had this before?
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #13
That's odd. I know that BMP works without SDL_image (SDL can handle doing BMPs). JPG and PNG I know are supported because I've used them both. I'm not sure about GIF.

What are jpeglib, zlib, and pnglib? Are they more image handling libraries? Try removing them so that you only have SDL_image. I don't know if that'll do anything but, again, it's worth a try.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #14
I think that gifs are covered by the jpeglib

Im trying to compile SDL_image from source, it requires libjpeg and libpng. libpng requires zlib.
Without those three compiling SDL_image works but becuase it disables use jpeg and png files.
Ive managed to compile and install zlib and libpng fine and SDL_image compiles only giving one error, cannot find libjpeg when it tests using -ljpeg,

I tried cp'ing libjpeg.a into /usr/local/lib
and jpelib.h into /usr/local/include
but it still doesnt work

Is there more I should do to fully install a library, or do I need to build .dylib's too?

Nup, just needed to ranlib /usr/local/lib/libjpeg.a
!!!!!
excelent it all works perfectly!!
Och, dammit gifs still dont.
Pngs and Jpegs do though.
Quote this message in a reply
scriabin
Unregistered
 
Post: #15
hi all.
i got sdl_image to work recently with the sdl application template but only after much confusion. i thought i had to add image support with separate dylibs and/or .a libs, which i added from finks dist, but was told later by the sdl newsgroup that adding these is unecessary and conflicts with the statically link libs that work with the sdl_image framework. ( dont ask me why , im a c newbie)Even though i could build, i had to remove all references to external libs to get the full working version of the SDL_image framework. at any rate, starting from a fresh sdl app template, after adding the SDL_image framework to the project, just adding in search paths
/Library/Frameworks/SDL_image.framework/Headers to Header,
/Library/Frameworks/ to Frameworks , and
-framework SDL_image
to Linker settings seems to work for all the formats now.

tod
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble using SDL_image with XCode 3.2.3 Snow Leopard code4fun 1 4,262 Sep 22, 2010 10:47 PM
Last Post: OneSadCookie
  SDL_image and bmp loading Duane 13 8,379 Dec 21, 2009 09:14 AM
Last Post: Skorche
  Installing SDL_image &amp; SDL_mixer bronxbomber92 8 5,542 Oct 14, 2006 09:39 PM
Last Post: szymczyk
  SDL_image + libpng + Panther = version mismatch BobbyWatson 2 4,034 Oct 23, 2005 03:55 AM
Last Post: BobbyWatson
  I Need help with SDL_image.h LidLad 8 4,795 Oct 2, 2005 05:37 PM
Last Post: LidLad