Ok so I've been trying to get SDL_image to work in Code::Blocks for the past 2 days to no avail.
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!
Can't get SDL_image to work
if ( IMG_Init( IMG_INIT_PNG ) != IMG_INIT_PNG ) {
printf( "Unable to initialize SDL_Image\n" );
return;
}
?
I have never used Code::Blocks so I cannot give you specific instructions, but I can provide some general tips and suggestions that could help you solve your problem. Can you compile and run a simple SDL program without SDL_image? If not, start with a SDL program without using SDL_image. Getting SDL working should make it simpler to get SDL_image working.
My code that uses SDL_image does not have the leading SDL/ in the include.
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.
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.
Mark Szymczyk
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com
Shouldn't SDL_image appear before SDL in the linker list? (i.e. SDL_image first, SDL second) Not giving a deep thought to this, but IIRC the libraries you depend upon should go last.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Thanks for the replies!
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!
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!
Ok this is just ridiculous, I try compiling with:
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?
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?
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() ??
[/quote]
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.
Also calling IMG_Init(IMG_INIT_PNG) again throws an undefined reference error. Yet IMG_INIT_PNG I can use and output normally.
[/quote]
IMG_INIT_PNG is probably a preprocessor constant.
I tried installing an older version of SDL_image, version 1.2.4 to be exact. And it works flawlessly.
[/quote]
Which version is causing you trouble? Where did you obtain this one?
Is this a bug or something in the code?
[/quote]
In your code? Probably not.
Wait a second!
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?
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.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
I released an update to the website tonight regarding this actually.
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.
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.
Learn to make games with my SDL 2 Tutorials
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement