Unable to load using sdl_image

I am not sure if this is a problem of having both SDL1 and 2 installed. Some people said that it was Img_Load and others said that it was IMG_Load. Boith though get either undefined or non existant. This is on Arch Linux.

Code:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include

class Control{
public:
SDL_Window* window = 0;
SDL_Renderer* renderer = 0;
std::string title;
int width = 0, height = 0;
bool running = true, fullscreen;

    SDL_Texture* texture; // the new SDL_Texture variable
    SDL_Rect source_rect; // the first rectangle
    SDL_Rect dest_rect; // another rectangle
    
    Control(std::string titlename, int window_width=0, int window_height=0, bool fullscr=false)
    : title(titlename), width(window_width), height(window_height), fullscreen(fullscr){
        if ( ! init()){
            //problem
        }
    }
    
    ~Control(){
        clean();
    }
    
    void clean(){
        SDL_DestroyWindow(window);
        SDL_DestroyRenderer(renderer);
        SDL_Quit();
    }
    
    bool init(){
        if (SDL_Init(SDL_INIT_EVERYTHING) == 0){
            int flags = 0;
            if (fullscreen){
                flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
            }
            window = SDL_CreateWindow(title.c_str(),
                SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 
                width, height,
                flags);
            if (window != 0){
                renderer = SDL_CreateRenderer(window, -1, 0);
            }
        }
        else{
            return false;
        }
        //Img_Load IMG_Load
        SDL_Surface* temp = IMG_Load("Pictures/1.png");
        texture = SDL_CreateTextureFromSurface(renderer, temp);
        SDL_FreeSurface(temp);
        SDL_QueryTexture(texture, NULL, NULL, &source_rect.w, &source_rect.h);
        dest_rect.x = source_rect.x = 0;
        dest_rect.y = source_rect.y = 0;
        dest_rect.w = source_rect.w;
        dest_rect.h = source_rect.h;

        return true;
    }
    
    void events(){
        SDL_Event event;
        if (SDL_PollEvent(&event)){
            switch (event.type){
                case SDL_QUIT:
                    running = false;
                    break;
                case SDL_KEYDOWN:
                    running = false;
                    break;
                default:
                    break;
            }
        }
    }
    
    void update(){
        
    }
    
    void render(){
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, &source_rect, &dest_rect);
        SDL_RenderPresent(renderer);
    }
    
    void run(){
        while (running){
            events();
            update();
            render();
        }
    }

};

int main(){
Control app(“SDL test”, 800, 600, false);
app.run();
}

Code:
/tmp/ccQDoZ9P.o: In function Control::init()': test4.cpp:(.text._ZN7Control4initEv[_ZN7Control4initEv]+0xb9): undefined reference toIMG_Load’
collect2: error: ld returned 1 exit status

command:

Code:
g++ -I/usr/include/SDL2 -std=c++11 -Wall -o “%e” “%f” -lSDL2 -LSDL_image &&"./%e"

header file

Code:
metulburr at arch /usr/include/SDL2 $ ls | grep SDL_image
SDL_image.h
metulburr at arch /usr/include/SDL2 $

lib files:

Code:
metulburr at arch /usr/lib $ ls | grep SDL
libSDL-1.2.so.0
libSDL-1.2.so.0.11.4
libSDL.so
libSDL2-2.0.so.0
libSDL2-2.0.so.0.1.0
libSDL2.so
libSDL2_image-2.0.so.0
libSDL2_image-2.0.so.0.0.0
libSDL2_image.a
libSDL2_image.la
libSDL2_image.so
libSDL_image-1.2.so.0
libSDL_image-1.2.so.0.8.4
libSDL_image.so
libSDL_mixer-1.2.so.0
libSDL_mixer-1.2.so.0.12.0
libSDL_mixer.so
libSDL_ttf-2.0.so.0
libSDL_ttf-2.0.so.0.10.1
libSDL_ttf.so
libSDLmain.a
metulburr at arch /usr/lib $

I did the usual on the downloaded SDL2_image-2.0.0
./configure
make
make install

You’re using SDL2. Only link to SDL2 and SDL2 libraries. Don’t let 2.0 (or
2.1) clash with 1.2.

After you do an surface = IMG_Load(), check if surface is NULL (or
nullptr). If it is, check what the IMG_GetError() is.
If the surface isn’t null, the image loaded successfully.

After you do an texture = SDL_CreateTextureFromSurface(), check if the
texture is NULL (or nullptr). If it is, check what the SDL_GetError() is.
If the texture isn’t null, the texture was created successfuly.On Sat, Dec 7, 2013 at 12:15 PM, metulburr2 wrote:

I am not sure if this is a problem of having both SDL1 and 2 installed.
Some people said that it was Img_Load and others said that it was IMG_Load.
Boith though get either undefined or non existant. This is on Arch Linux.

Code:

#include
#include
#include

class Control{
public:
SDL_Window* window = 0;
SDL_Renderer* renderer = 0;
std::string title;
int width = 0, height = 0;
bool running = true, fullscreen;

    SDL_Texture* texture; // the new SDL_Texture variable
    SDL_Rect source_rect; // the first rectangle
    SDL_Rect dest_rect; // another rectangle

    Control(std::string titlename, int window_width=0, int

window_height=0, bool fullscr=false)
: title(titlename), width(window_width), height(window_height),
fullscreen(fullscr){
if ( ! init()){
//problem
}
}

    ~Control(){
        clean();
    }

    void clean(){
        SDL_DestroyWindow(window);
        SDL_DestroyRenderer(renderer);
        SDL_Quit();
    }

    bool init(){
        if (SDL_Init(SDL_INIT_EVERYTHING) == 0){
            int flags = 0;
            if (fullscreen){
                flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
            }
            window = SDL_CreateWindow(title.c_str(),
                SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                width, height,
                flags);
            if (window != 0){
                renderer = SDL_CreateRenderer(window, -1, 0);
            }
        }
        else{
            return false;
        }
        //Img_Load IMG_Load
        SDL_Surface* temp = IMG_Load("Pictures/1.png");
        texture = SDL_CreateTextureFromSurface(renderer, temp);
        SDL_FreeSurface(temp);
        SDL_QueryTexture(texture, NULL, NULL, &source_rect.w,

&source_rect.h);
dest_rect.x = source_rect.x = 0;
dest_rect.y = source_rect.y = 0;
dest_rect.w = source_rect.w;
dest_rect.h = source_rect.h;

        return true;
    }

    void events(){
        SDL_Event event;
        if (SDL_PollEvent(&event)){
            switch (event.type){
                case SDL_QUIT:
                    running = false;
                    break;
                case SDL_KEYDOWN:
                    running = false;
                    break;
                default:
                    break;
            }
        }
    }

    void update(){

    }

    void render(){
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, &source_rect, &dest_rect);
        SDL_RenderPresent(renderer);
    }

    void run(){
        while (running){
            events();
            update();
            render();
        }
    }

};

int main(){
Control app(“SDL test”, 800, 600, false);
app.run();
}

Code:

/tmp/ccQDoZ9P.o: In function Control::init()': test4.cpp:(.text._ZN7Control4initEv[_ZN7Control4initEv]+0xb9): undefined reference toIMG_Load’
collect2: error: ld returned 1 exit status

command:

Code:

g++ -I/usr/include/SDL2 -std=c++11 -Wall -o “%e” “%f” -lSDL2 -LSDL_image
&&"./%e"

header file

Code:

metulburr at arch /usr/include/SDL2 $ ls | grep SDL_image
SDL_image.h
metulburr at arch /usr/include/SDL2 $

lib files:

Code:

metulburr at arch /usr/lib $ ls | grep SDL
libSDL-1.2.so.0
libSDL-1.2.so.0.11.4
libSDL.so
libSDL2-2.0.so.0
libSDL2-2.0.so.0.1.0
libSDL2.so
libSDL2_image-2.0.so.0
libSDL2_image-2.0.so.0.0.0
libSDL2_image.a
libSDL2_image.la
libSDL2_image.so
libSDL_image-1.2.so.0
libSDL_image-1.2.so.0.8.4
libSDL_image.so
libSDL_mixer-1.2.so.0
libSDL_mixer-1.2.so.0.12.0
libSDL_mixer.so
libSDL_ttf-2.0.so.0
libSDL_ttf-2.0.so.0.10.1
libSDL_ttf.so
libSDLmain.a
metulburr at arch /usr/lib $

I did the usual on the downloaded SDL2_image-2.0.0
./configure
make
make install


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Only link to SDL2 and SDL2 libraries. Don’t let 2.0 (or 2.1) clash with 1.2.

I am not sure exactly how i am letting 1.2 clash with 2?

After you do an surface = IMG_Load(), check if surface is NULL (or nullptr). If it is, check what the IMG_GetError() is.

If the surface isn’t null, the image loaded successfully.

After you do an texture = SDL_CreateTextureFromSurface(), check if the texture is NULL (or nullptr). If it is, check what the SDL_GetError() is.

If the texture isn’t null, the texture was created successfuly.

Code:
SDL_Surface* temp = IMG_Load(“Pictures/1.png”);
if (temp == NULL){
std::cout << IMG_GetError() << std::endl;
}
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (texture == NULL){
std::cout << SDL_GetError() << std::endl;
}

thanks for the info, ill test it as soon as i can compile it.

EDIT:
i changed it to link to SDL2_image

Code:
-LSDL2_image

but i get the same error as well?

Code:
/tmp/cc3x0Kax.o: In function Control::init()': test4.cpp:(.text._ZN7Control4initEv[_ZN7Control4initEv]+0xb9): undefined reference toIMG_Load’
collect2: error: ld returned 1 exit status

EDIT:
i changed it to link to SDL2_image

Code:
-LSDL2_image
you should use ‘-l’ instead, as ‘-L’ specifies just a library search
path, not the library itself.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20131207/eed0af08/attachment-0001.pgpOn Sat, 07 Dec 2013 11:46:56 +0000 “metulburr2” wrote:

2013/12/7 metulburr2

command:

Code:

g++ -I/usr/include/SDL2 -std=c++11 -Wall -o “%e” “%f” -lSDL2 -LSDL_image
&&"./%e"

Since you’re on Linux, why not use pkgconfig for the g++ flags?

g++ -std=c++11 -Wall -o “%e” “%f” pkg-config --cflags --libs sdl2 SDL2_image

This way you won’t mix up library/include paths.

metulburr2 wrote:

EDIT:
i changed it to link to SDL2_image

Code:
-LSDL2_image

but i get the same error as well?

Code:
/tmp/cc3x0Kax.o: In function Control::init()': test4.cpp:(.text._ZN7Control4initEv[_ZN7Control4initEv]+0xb9): undefined reference toIMG_Load’
collect2: error: ld returned 1 exit status

Looks like a typo issue. “-L” and “-l” (upper vs lower case) mean two completely different things - the lowercase tells the compiler to use the specified library, while the uppercase version adds a directory to the library search path.

So try with “’-lSDL2_image” rather than “-LSDL2_image” and see what happens.

Looks like a typo issue. “-L” and “-l” (upper vs lower case) mean two completely different things - the lowercase tells the compiler to use the specified library, while the uppercase version adds a directory to the library search path.

So try with “’-lSDL2_image” rather than “-LSDL2_image” and see what happens.

oh thanks. This was the problem. I for some reason didn’t even catch the fact that i was capping the L.