• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
OmarShehata

Can't get SDL_image to work

7 posts in this topic

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 [url="http://www.threelas.com/2011/07/how-to-install-sdlimage-in-codeblocks.html"]convieniant video tutorial.[/url] 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!
0

Share this post


Link to post
Share on other sites
[code]
if ( IMG_Init( IMG_INIT_PNG ) != IMG_INIT_PNG ) {
printf( "Unable to initialize SDL_Image\n" );
return;
}
[/code]

?
0

Share this post


Link to post
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.

[CODE]#include "SDL_image.h"[/CODE]

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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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:

[img]http://www.4urentertainment.org/Links.png[/img]

I'm not sure what else to do.

Again, any help is appreciated and thank you for the responses!
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
[quote]
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.

[quote]
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.

[quote]
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?

[quote]
Is this a bug or something in the code?
[/quote]
In your code? Probably not.
0

Share this post


Link to post
Share on other sites
Wait a second!

[quote name='OmarShehata' timestamp='1329194626' post='4912881']
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?
[/quote]
Which version did you have? Because all the SDL satellite libraries got a new version to make them work with SDL 2.0. [b]They will not work with SDL 1.2.[/b] You need to make sure your SDL_image version was made for your SDL version.
1

Share this post


Link to post
Share on other sites
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.
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0