Jump to content
  • Advertisement
Sign in to follow this  
password

SDL IMG_Load

This topic is 4522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi.. I'm currently reading the Lazy Foo productions tutorial on SDL and can't get it to work, the image extension library that is. I've extracted the necessary lib files, dll files and the include file to the right folders. I've also extracted all the dll files into the system32 folder, i'm using the paramter -ISDL_image and yes I have the other parameters too (-lmingw32 -lSDLmain -lSDL). I don't get any compiler errors, but a linker error which is the following: undefined reference to `IMG_Load' I'm using dev c++ and this is the only code block that use IMG_Load.
[SOURCE]
SDL_Surface *load_image(std::string filename) {
    //Temporary storage for the image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = IMG_Load(filename.c_str());

    //If nothing went wrong in loading the image
    if (loadedImage != NULL) {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat(loadedImage);

        //Free the old image
        SDL_FreeSurface(loadedImage);
    }

    return optimizedImage;
}
[/SOURCE]
I have searched around everywhere but haven't found anything that could help me, thankful for help..

Share this post


Link to post
Share on other sites
Advertisement
Well, you also need to link the SDL_Image, that is,
-lSDL_Image
(note: that is a little el, not a big ai)

Share this post


Link to post
Share on other sites
You could try rearranging the order of your linked libs. That makes a difference for MinGW I think.

Sorry I can't be more specific.

Share this post


Link to post
Share on other sites
Quote:
Original post by Simian Man
You could try rearranging the order of your linked libs. That makes a difference for MinGW I think.

Sorry I can't be more specific.


The perfect order is:

-lmingw32
-lSDLmain
[other sdl libs]
-lSDL
[if you have any opengl stuff]


Atleast it works for me :).

Share this post


Link to post
Share on other sites
This is the complete parameter list in order i'm using:
-lmingw32 -lSDLmain -lSDL -ISDL_Image

prog.cpp: undefined reference to `IMG_Load'

This is really frustruating, can't continue reading if it doesn't become right. It's only one function and that is IMG_Load, I hate illogical errors like these that should be right, but are filled with errors even so.

Well, anyways, if someone knows anything about this, please post here, will search around some more about it.

Share this post


Link to post
Share on other sites
Sharlin already told you the solution!

use
-lSDL_Image
instead of
-ISDL_Image

(have a closer look at the first character before "SDL_Image"....)

Share this post


Link to post
Share on other sites
Ok, to elaborate:

* The -Idirectory (big ai) argument tells the compiler to search for header files from that directory in addition to the default ones.

* But the -llibrary (little ell) argument, instead, tells the linker to link the given library to the executable.

In this case, you need both of those arguments for the compiling to succeed.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sharlin
Ok, to elaborate:

* The -Idirectory (big ai) argument tells the compiler to search for header files from that directory in addition to the default ones.

* But the -llibrary (little ell) argument, instead, tells the linker to link the given library to the executable.

In this case, you need both of those arguments for the compiling to succeed.


I didn't.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No really, the linker parameters should be like this:

-lmingw32
-lSDLmain
-lSDL
-lSDL_image

Notice the little L at the start in each case.
Also make sure you've extracted the bits of the image package appropriately..

SDL_image.lib from SDL_image-1.2.4/lib to Dev-Cpp/lib

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!