View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Problem with SDL (Undefined Reference)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1DaShwimp  Members

Posted 07 August 2012 - 03:12 PM

Hi, Im relatively new to programming. I know quite a bit about C++ and want to try to make a game so I started doing Lazy Foo's SDL tutorial.
Im using CodeBlocks 10.05 with GNU GCC compiler.
I got to Tutorial 4 and now Im completely stuck.

All that ever happens is I get the error "Undefined Reference to IMG_Load"

obj\Debug\source3.o||In function Z10load_imageSs':|
||=== Build finished: 1 errors, 0 warnings ===|

My linker options are set up as:
-lmingw32
-lSDLmain
-lSDL_image
-lSDL

I have the SDL.dll with the project folder
In the projects bin/Debug folder I have 6 .dll's and a .lib
libjpeg-8.dll
libpng15-15.dll
libtiff-5.dll
libwebp-2.dll
SDL_image.dll
zlib1.dll
SDL_image.lib

In the source files properties, I have Compile File, Link File, Debug, and Release all enabled, the SDL headers are included, and all the directories to SDL files and folders are all correct.

I can attach the source file if it helps at all.
Any help is really appreciated. I have been searching for days, hours on end for a solution and most posted solutions are changing the settings to something I already have set up.

Posted 07 August 2012 - 03:44 PM

show some source code?

### #3bluehailex  Members

Posted 07 August 2012 - 04:41 PM

Try putting -lSDL_image at the top. The problem is you are trying to use IMG_Load(), which is defined in SDL_Image. The linker can be a bit stupid with Code::Blocks, so you might have to rearrange the options.

Also, I don't see a need for SDL_image.lib to be in you output directory.

Edited by bluehailex, 07 August 2012 - 04:44 PM.

### #4DaShwimp  Members

Posted 07 August 2012 - 05:08 PM

Thanks for the replies, here is the source code

I tried putting -lSDL_image at the top and it didnt change anything :\

### #5bluehailex  Members

Posted 07 August 2012 - 10:56 PM

It is possible you are linking with the wrong SDL_image library. You might be using an x64 build, when you really are x86. Or you may have even downloaded the wrong SDL_image zip all together from here. I don't think there is anything wrong with your code.

### #6DaShwimp  Members

Posted 07 August 2012 - 11:57 PM

Thanks so much for the replies so far

### #7bluehailex  Members

Posted 08 August 2012 - 06:13 PM

Try linking directly with the libraries by supplying the absolute path to them instead of giving the linker options. For example: "C:\Dev\Lib\SDL\SDL_image.lib" Make sure you put the paths in the "Link Libraries" section, not "Other linker options".

Posted 08 August 2012 - 06:57 PM

Is it possible just somehow it is a lowercase L instead of an capital i ? I know its a far shot lol

### #9DaShwimp  Members

Posted 08 August 2012 - 07:17 PM

I know its not a capital i lolz xD

bluehailex your solution seemed to work!
Except now it just closes instantly with the message:
"Process terminated with status 1 (0 minutes, 0 seconds)"
So now I need to like look around and try to find out that problem!
Thanks so much! If you can maybe offer some advice for the current problem or using SDL in general, thatd be great

### #10bluehailex  Members

Posted 08 August 2012 - 09:07 PM

Either something didn't build quite right, or CodeBlocks cannot find your output executable. Try running your program from the explorer.

As for SDL in general, it is a great library. Very portable, but it doesn't come with the greatest performance out of the box. It uses software rendering, as opposed to hardware rendering (using the GPU). If you are planning on doing your own rendering in OpenGL, it will work out very well. However, there is a similar library called SFML. It uses hardware rendering by default, and will give you great performance compared to SDL. I haven't used SDL in a while, so things may have changed. SFML was written in C++ and is object oriented, while SDL was written in C and is not object oriented.

SDL and SFML both support Windows/Linux/Mac/FreeBSD, but SDL goes even further to support consoles and even some mobile operating systems. SFML is pretty active, so I would not be surprised if it gets ported to consoles/mobile devices as well.

### #11DaShwimp  Members

Posted 09 August 2012 - 12:02 AM

Thanks so much for all the help

Would you recommend any in particular? Like which one is easier for someone to pickup and go with?
Im not too concerned with mobile though

Edit:
Toying around a bit, I found that the build error is coming in the load_files function, namely it is returning false no matter what.
I had this before in another load_image instance and I just had to remake the file, but it isn't working here. Any tips? lolz xP
Edit:
Nevermind! Got it, I had the x.png in the debug folder, when it needed to be in the project folder!
Thank you SO much!! You have no idea how awesome it is to have this working xD

Edited by DaShwimp, 09 August 2012 - 12:15 AM.

### #12bluehailex  Members

Posted 09 August 2012 - 08:18 AM

Glad I could help. SFML is probably going to be easier for you to learn, but once you built a simple framework around SDL or SFML it wont matter.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.