This topic is 4344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi.. I'm currently reading the Lazy Foo productions tutorial on SDL and can't get it to work, the image extension library that is. I've extracted the necessary lib files, dll files and the include file to the right folders. I've also extracted all the dll files into the system32 folder, i'm using the paramter -ISDL_image and yes I have the other parameters too (-lmingw32 -lSDLmain -lSDL). I don't get any compiler errors, but a linker error which is the following: undefined reference to IMG_Load' I'm using dev c++ and this is the only code block that use IMG_Load.
[SOURCE]
//Temporary storage for the image that's loaded

//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;

//Create an optimized image

//Free the old image
}

return optimizedImage;
}
[/SOURCE]
I have searched around everywhere but haven't found anything that could help me, thankful for help..

##### Share on other sites
Well, you also need to link the SDL_Image, that is,
-lSDL_Image
(note: that is a little el, not a big ai)

##### Share on other sites
Like I said, i've already linked to that, do you know any other reason it could be like this?

##### Share on other sites
You could try rearranging the order of your linked libs. That makes a difference for MinGW I think.

Sorry I can't be more specific.

##### Share on other sites
Quote:
 Original post by Simian ManYou could try rearranging the order of your linked libs. That makes a difference for MinGW I think.Sorry I can't be more specific.

The perfect order is:
-lmingw32-lSDLmain[other sdl libs]-lSDL[if you have any opengl stuff]

Atleast it works for me :).

##### Share on other sites
This is the complete parameter list in order i'm using:
-lmingw32 -lSDLmain -lSDL -ISDL_Image

This is really frustruating, can't continue reading if it doesn't become right. It's only one function and that is IMG_Load, I hate illogical errors like these that should be right, but are filled with errors even so.

##### Share on other sites
Sharlin already told you the solution!

use
-lSDL_Image
-ISDL_Image

(have a closer look at the first character before "SDL_Image"....)

##### Share on other sites
Ok, to elaborate:

* The -Idirectory (big ai) argument tells the compiler to search for header files from that directory in addition to the default ones.

* But the -llibrary (little ell) argument, instead, tells the linker to link the given library to the executable.

In this case, you need both of those arguments for the compiling to succeed.

##### Share on other sites
Quote:
 Original post by SharlinOk, to elaborate: * The -Idirectory (big ai) argument tells the compiler to search for header files from that directory in addition to the default ones. * But the -llibrary (little ell) argument, instead, tells the linker to link the given library to the executable. In this case, you need both of those arguments for the compiling to succeed.

I didn't.

##### Share on other sites
No really, the linker parameters should be like this:

-lmingw32
-lSDLmain
-lSDL
-lSDL_image

Notice the little L at the start in each case.
Also make sure you've extracted the bits of the image package appropriately..

SDL_image.lib from SDL_image-1.2.4/lib to Dev-Cpp/lib

##### Share on other sites
Sorry, didn't understand that it was supposed to be a l instead of an i. Anyways the error disappeared now, but it says that it doesn't exists instead (linker error).

That's really strange because it didn't say that when the paramter was "i", which is the one that should return that message. Now when the right parameter is in place it returns the doesn't exist error, really odd.

##### Share on other sites
Quote:
 Original post by passwordSorry, didn't understand that it was supposed to be a l instead of an i. Anyways the error disappeared now, but it says that it doesn't exists instead (linker error).That's really strange because it didn't say that when the paramter was "i", which is the one that should return that message. Now when the right parameter is in place it returns the doesn't exist error, really odd.

you forgot this step:
Quote:
 From the tutorialNext extract the lib file that's inside of lib subfolder of the archive to the Dev C++ lib folder.The Dev C++ lib folder should be at C:\Dev-Cpp\lib.

and it's not strange. The first time it was complaining that you never told it where the function was (which is what a lib file does), and now it's complaining it can't find the lib file you're trying to link against.

##### Share on other sites
I have already extracted all files including the lib file (SDL_image.lib).

##### Share on other sites
copy/paste the error as it appears in the compiler.

##### Share on other sites
C:\DEV-C_~1\Bin\ld.exe: cannot open -lSDL_image: No such file or directory

##### Share on other sites
that means SDL_image.lib is not in C:\DEV-C_~1\lib or you put -l-lSDL_image

double check.

##### Share on other sites
Does mingw load <whatever>.lib files with the -l parameter? I thought it only loaded lib<whatever>.a files, maybe Im wrong.

For SDL_Image, I've always used the file libSDL_image.a (not SDL_image.lib, i may have downloaded a devpack or compiled it myself, i can't remember, i installed it long ago...) and have never had problems. For .lib's I've always added the full path (eg: whatever/dev-cpp/lib/foo.lib instead of -lfoo or if the file was libfoo.a i use -lfoo).

##### Share on other sites
Quote:
 Original post by Lazy Foothat means SDL_image.lib is not in C:\DEV-C_~1\lib or you put -l-lSDL_imagedouble check.

Maybe he DOES have THAT, but that won't matter. He probably doesn't have libSDL_Image.a.

[grin][wink]

##### Share on other sites
In my /DevCpp/lib dir, I have the files "SDL_ttf.lib" AND "libSDL_image.a" and both of them work the exact same way in the parameters tab - that is, I use -lSDL_ttf -lSDL_image. Works fine.

##### Share on other sites
I can test the libSDL_image.a file if you say that is working, but where can I get it?

##### Share on other sites
I'm pretty sure I got it from here using the "SDL_image-devel-1.2.4-VC6.zip" file. It has SDL_image.lib; I don't remember if I renamed this file to libSDL_image.a or not but I definitely do have libSDL_image.a in my compiler's lib folder. I guess that's what I did.

Hey: I tried renaming libSDL_image.a to SDL_image.lib and I could still compile projects dependent on SDL_image fine! Either way you'll need the file if you don't have it, but it looks like renaming it is optional. I wonder why I did it originally?

##### Share on other sites
Damn, it still doesn't work, why do these illogical errors keep bugging me wherever I go, they always appear where I am!

I've tried many things now, renamed the -lSDL_image parameter to these things:
-SDL_image
-SDL_image.lib
-lSDL_image.lib
-llibSDL_image.a
-libSDL_image.a
-lc:\dev\lib\SDL_image
-l\dev\lib\SDL_image

have also tried to rearrange the order countless times, with all those combinations aswell. It should find it, i've copied the file in every folder in dev-c++. It keeps saying that it doesn't find the file, these kind of errors seem to be unsolveable.

##### Share on other sites
I don't think you answered a couple of the questions above:
- Do you have libSDL_image.a?
- If so, is it in the correct directory?
- And where did you get it from?

I don't think you can get away with just renaming a .lib as a .a file. One is for Microsoft compilers and one is not.

##### Share on other sites
I originially thought that the differences between the library version (MSVC vs. MinGW) were your problem, but this says that it's a straight C library and the MinGW linker should be able to link against it.

I found this on the web about setting up SDL_image with MinGW at http://gpwiki.org/index.php/SDL:Tutorials:Setup

Quote:
 MinGW and SDL_imageSDL_image is an invaluable add-on library that allows you to use a wide variety of image formats with SDL, including BMP, JPG, GIF, PNG, TGA, PCX and many more (as opposed to just BMPs with SDL alone).If you want to get up and running quickly without re-compiling from source, simply grab the runtime development package. This time however, you can use the MSVC package. You can link directly to the SDL_image.lib file as it only requires plain vanilla C linkage (no C++ or other MinGW-specific WinMain). Just extract the archive to a location and remember to set the include and lib paths when you compile.The documentation site for SDL_image is clear and straightforward. It also has an excellent example source to try which serves as a great little intro to both SDL and SDL_Image at the same time. Assuming your SDL/ and SDL_image/ directories are at the same level, create another folder at that same level, called viewimage. Grab the viewimage.c source from the demos directory, as well as a few image files to test. Put the files you download in the viewimage folder. Then you can use this makefile to build the test app:make -f viewimage.makefileMinIDE users will just build an SDL project as usual, but add the SDL_image.lib file to the project by dragging that file's icon into the target window, and adding ../SDL_image/include to the include path.Finally, copy all the .dll files (zlib.dll, jpeg.dll, libpng1.dll, SDL_image.dll and SDL.dll) to the viewimage directory so the app can find them when you run it. The app is a command-line app, so pull up a command prompt and cd to that directory. Test it by running it with the name of one of the demo images:

Cheers,

Bob

[Edited by - Scourage on April 2, 2006 2:11:51 PM]

##### Share on other sites
I have had similar troubles statically linking to SDL_image across various compilers. Since it is one dll/so with one (useful) entry point, I would recommend just loading it dynamically.

In SDL, something like this (I haven't compiled it):

void* handle = SDL_LoadObject( "SDL_image" );

will find the IMG_Load for you. You will have to put in some #ifdefs to load the correct filename: SDL_image, SDL_image.so, or SDL_image.dylib. But overall I find, for this case, a dynamic load easier to get working.

lee