0

I have a code that I found on github:

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

#define WIDTH 800
#define HEIGHT 600
#define IMG_PATH "exit.png"

int main (int argc, char *argv[]) {
    SDL_Window *win = NULL;
    SDL_Renderer *renderer = NULL;
    SDL_Texture *img = NULL;
    int w, h; 
    
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
            return 1;
    
    win = SDL_CreateWindow("Image Loading", 100, 100, WIDTH, HEIGHT, 0);
    renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
    
    img = IMG_LoadTexture(renderer, IMG_PATH);
    SDL_QueryTexture(img, NULL, NULL, &w, &h); 

    SDL_Rect texr; texr.x = WIDTH/2; texr.y = HEIGHT/2; texr.w = w*2; texr.h = h*2; 

    while (1) {
        SDL_Event e;
        if ( SDL_PollEvent(&e) ) {
            if (e.type == SDL_QUIT)
                break;
            else if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_ESCAPE)
                break;
        } 
        SDL_RenderClear(renderer);
        
        SDL_RenderCopy(renderer, img, NULL, &texr);
        
        
        SDL_RenderPresent(renderer);
    }
    
    SDL_DestroyTexture(img);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(win);

    return 0;
}

when I try to compile it with: gcc main.c -Wfatal-errors -std=c89 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

it fails with the error msg: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Asus\AppData\Local\Temp\ccHk4p0j.o:main.c:(.text+0x9c): undefined reference to `IMG_LoadTexture' collect2.exe: error: ld returned 1 exit status

In the MinGW\bin folder I have the SDL2_image.dll, and in the MinGW\lib folder I have libSDL2_image.a, and .dll.a, and .la The SDL2 works nicely and I don't get what could be wrong/different with SDL_image in my case.

vapandris
  • 27
  • 5

0 Answers0