“Undefined Reference To 'IMG_Load'” CodeBlocks and SDL_Image Error

closed account (L3ME3TCk)
I had this problem for 2 days now. I'm learning SDL through Lazy Foo's tutorial, but I can't proceed further as IMG_Load doesn't seem to work. I tried setting it up like he says, but it just doesn't work. I put all the include files into include folder, and all the lib files into the lib folder. What I found is that there were x86 and x64 folders in the lib folder. When I tried x64 (because I have a 64-bit system)it all worked fine, CodeBlocks even told me suggestions (like when I wrote "img" it showed up a suggestion "IMG_Load" (which means the library got initalized?)), but when I come to compiling my code, this happens: http://puu.sh/3Eqa5.png . When I try with the x86 version, exact same error.

I had a little search around the internet, and all I could find were a few threads, but most of them were abandoned. The closest I got to answering my problem was this: http://www.dreamincode.net/forums/topic/118299-sdl-image-error-sdl/ but the guy solved his problem by downloading a problem which Linux can use, not Windows. }

I'm running Windows 7 64-bit, CodeBlocks 12.11, SDL 1.2.15 and SDL_Image 1.2.12.

I really don't know what the problem is! Any help is appreciated.
#including the header is only one part of it.

You also have to link to the .lib file, which you must not be doing.

Simply putting the .lib files in a directory is not enough. You also have to add the lib file names to your project settings so the linker knows to link to them.

I would be very surprised if the LazyFoo tutorials did not explain how to do this.

(these directions might not be 100% correct, but you should be able to figure it out)
-) Right click on your project in the solution explorer
-) Go to properties
-) Somewhere in the "linker" properties there's an "input" field
-) Add the necessary .lib filenames to that field.
-) Hit OK
-) Rebuild



EDIT: I just realized you said C::B --- for some reason I thought you were using VS. C::B is similar but it might not call it "solution explorer". Just find out where C::B puts your linker settings.
Last edited on
closed account (L3ME3TCk)
I already did this :/ I have everything included in the linker options too.
The error is telling you the linker could not find any definition for the IMG_Load function.

Assuming:
1) You are properly linking to the required library
and
2) The library has a definition for IMG_Load


Then you would not be getting this error.

So one of those 2 things must not be the case. I'm 99% sure the problem is with #1, but if you are SURE you are linking properly I suppose it's possible your lib is bad and isn't exporting IMG_Load like it needs to be, in which case I would recommend rebuilding the SDL_Image library from its source.
Are you sure that you use the right libraries? I mean for the compiler you're using?
well I don't know how to use C::B I can say only the command line for G++

compiling

 
g++ -c -I"PATH/TO/SDL/INCLUDES" -I"PATH/TO/SDL_IMAGE/INCLUDES" -o module.o module.cpp


* WARNINGS: I don't remember if SDL requires extra_defines. I have an example of SDL elsewhere, not here. In case... add -D params for every extra_define required... example -DHAVE_MACRO to define HAVE_MACRO

Replace "path/to/SDL*/INCLUDES" with the path where include files of SDL* are actually stored

linking

1
2
3
g++ -mwindows -L"PATH/TO/SDL/LIB" -L"PATH/TO/SDL_IMAGE/LIB" \
-o myprogram.exe module1.o module2.o main.o \
-lmingw32 -lSDLmain -lSDL -lSDL_Image


you can remove all \ and attach all to a single line.... I wrote it multilined in order to graphic reasons here.

I am not sure about the exact placement of -mwindows. If linking returns some error, try to change orders on parameters.... I have a project where I used SDL_Mixer together with Qt so I will be able to confirm you the right order when I come back to home
Last edited on
closed account (L3ME3TCk)
SOLVED MY PROBLEM:
I installed SDL_Image 1.2.10 and it works ;D Thanks for all the help!
Topic archived. No new replies allowed.