#1 Members - Reputation: 184
Posted 09 February 2012 - 01:16 AM
I've followed both Lazyfoo's tutorial and this convieniant video tutorial. But I just keep getting the same error:
"undefined reference to `IMG_Load' "
I have the SDL_image.h in the include folder, where all the headers are.
I have SDL_image.lib in the lib folder, where all the .a files are.
I have in my linker options: -lmingw32 -lSDLmain -lSDL -lSDL_image
I have in my code: #include "SDL/SDL_image.h" (as well as including SDL itself)
And then I simply try "IMG_Load("anything.png")" and I get that error. Is there any reason why I would be getting this?
Any help would be appreciated, thanks!
#2 Members - Reputation: 180
Posted 10 February 2012 - 03:14 PM
My code that uses SDL_image does not have the leading SDL/ in the include.
#include "SDL_image.h"
You may need to add the SDL_image library to your project.
Loading PNG files with SDL_image on Windows requires several DLLs to be in the proper location, which should be the same directory as your executable file. At a minimum PNG loading requires the following DLLs: SDL_image.dll, libpng.dll, and zlib.dll. The libpng and zlib DLLs have a version number in the file name.
#3 Members - Reputation: 956
Posted 10 February 2012 - 06:17 PM
#4 Members - Reputation: 184
Posted 11 February 2012 - 04:21 AM
szymczyk, I am actually running SDL alone very nicely, and I can load bitmaps no problems, and move them around and whatnot. I just want to get a PNG imported now. I checked that all the dll's were there in both my exe directory and project directory. I removed SDL_image.h and tried to compile, it said that the directory didn't exist, so I put it back, and no errors there so I know it's correctly importing SDL_image.h
Sik_the_hedgehog, I changed the order to what you said, and still, I get the same error. I reverted it back to the order as stated here: http://lazyfoo.net/SDL_tutorials/lesson03/windows/codeblocks/index.php
What I don't get is how, even though when I type in "IMG_" the suggestions come up showing all the functions/classes I can use, including "IMG_Load()" and yet, compiling says it's undefined.
How can I know whether the SDL_image library is correctly included? This is what I have in my compiler settings:

I'm not sure what else to do.
Again, any help is appreciated and thank you for the responses!
#5 Members - Reputation: 184
Posted 13 February 2012 - 10:43 PM
IMG_GetError(), and it compiles with no undefined references whatsoever. Isn't this a function in SDL_Image? So that means it's being loaded properly, but why does it still give an undefined reference error for IMG_Load() ??
Also calling IMG_Init(IMG_INIT_PNG) again throws an undefined reference error. Yet IMG_INIT_PNG I can use and output normally.
I'm really confused on why this simply won't work. Any help whatsoever, any suggestions or anything I could try, would be greatly appreciated, thanks!
EDIT: So after much searching, apparently there's tons of forum questions around asking the same thing, with either no one knowing why it's not working, or it working by some random suggestion that works for some people but doesn't for others.
I tried installing an older version of SDL_image, version 1.2.4 to be exact. And it works flawlessly. I don't understand why the new version doesn't. Is this a bug or something in the code?
#6 Moderators - Reputation: 5028
Posted 14 February 2012 - 03:41 AM
IMG_GetError() is likely just a macro that calls SDL_GetError(). That is, the compiler just sees a call to SDL_GetError(), which it emits and the linker can satisfy.IMG_GetError(), and it compiles with no undefined references whatsoever. Isn't this a function in SDL_Image? So that means it's being loaded properly, but why does it still give an undefined reference error for IMG_Load() ??
IMG_INIT_PNG is probably a preprocessor constant.Also calling IMG_Init(IMG_INIT_PNG) again throws an undefined reference error. Yet IMG_INIT_PNG I can use and output normally.
Which version is causing you trouble? Where did you obtain this one?I tried installing an older version of SDL_image, version 1.2.4 to be exact. And it works flawlessly.
In your code? Probably not.Is this a bug or something in the code?
#7 Members - Reputation: 956
Posted 14 February 2012 - 04:29 PM
Which version did you have? Because all the SDL satellite libraries got a new version to make them work with SDL 2.0. They will not work with SDL 1.2. You need to make sure your SDL_image version was made for your SDL version.I tried installing an older version of SDL_image, version 1.2.4 to be exact. And it works flawlessly. I don't understand why the new version doesn't. Is this a bug or something in the code?
#8 Members - Reputation: 1029
Posted 19 February 2012 - 12:22 AM
When grabbing the library files, did you get the x86 or the x64 versions? When compiling, most compilers compile to 32bit. You should be using the x64 libraries only if you're compiling a 64bit binary, not if you're using a 64 operating system.
Transition from OpenGL 2 to modern OpenGL using my OpenGL Tutorial.






