0

I've got the following piece of code attempting to use SDL_image;

#include <iostream>
#define SDL_MAIN_HANDLED
#include <SDL.h>
#include <SDL_image.h>

int WIDTH = 800;
int HEIGHT = 800;

int main(int argc, char *argv[])
{   
    
    if (SDL_Init(SDL_INIT_VIDEO) > 0) {
        std::cout << "SDL INIT FAILED" << SDL_GetError() << std::endl;
    }

    SDL_Window* window = SDL_CreateWindow("Chaturanga", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);
    
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

    if (NULL == window)
    {
        std::cout << "Could not create window: " << SDL_GetError() << std::endl;
        return 1;
    }

    SDL_Texture* boardTexture = IMG_LoadTexture(renderer, "res/images/board.png");

    if (boardTexture == NULL) {
        std::cout << "Failed to load texture. Error: " << SDL_GetError() << std::endl;
    }

    SDL_Event windowEvent;

    while (true)
    {
        if (SDL_PollEvent(&windowEvent))
        {
            if (SDL_QUIT == windowEvent.type)
            {break;}
        }
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, boardTexture, NULL, NULL);
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyWindow(window);
    SDL_Quit();

    return EXIT_SUCCESS;
}

When I compile with:

g++ src/*.cpp -o main.exe -I lib/SDL2_lib/include -L lib/sdl2_lib/libr -L lib/sdl2_lib -lsdl2 -lsdl2_image

I get the following error; Error Image

My file structure is as follows, all functionality not relating to sdl image works fine.

enter image description here

Yes, the sdl_image.h file is in include; Inside the libr folder:

enter image description here

genpfault
  • 51,148
  • 11
  • 85
  • 139
Tah
  • 41
  • 1
  • 7
  • Probably a wrong `libSDL2_image[.dll].a`? An x32 one with an x64 compiler, or vice versa. Also an obligatory reminder that `SDL_MAIN_HANDLED` is a hack and shouldn't bee necessary, see [How do I use SDL2 in my programs correctly?](https://stackoverflow.com/q/64396979/2752075). – HolyBlackCat Jun 28 '22 at 04:19
  • Yep, you were right, can you create an actual answer so I can flag you as right – Tah Jun 28 '22 at 04:24
  • I can't, because the question is already closed. But I don't need to, because I've already made a comprehensive guide on this, which I've added to the questions your is closed as a duplicate of. – HolyBlackCat Jun 28 '22 at 04:26
  • It was more if you wanted rep but thanks anyways – Tah Jun 28 '22 at 08:20

0 Answers0