g cc не может найти SDL_image - PullRequest
       28

g cc не может найти SDL_image

0 голосов
/ 02 августа 2020

У меня есть код, который я нашел на 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;
}

, когда я пытаюсь скомпилировать его с помощью: g cc main. c -Wfatal-errors -std = c89 -lmingw32 - lSDL2main -lSDL2 -lSDL2_image

происходит сбой с сообщением об ошибке: c: / mingw / bin /../ lib / gcc / mingw32 / 9.2.0 /../../../. ./mingw32/bin/ld.exe: C: \ Users \ Asus \ AppData \ Local \ Temp \ ccHk4p0j.o: main. c :(. text + 0x9 c): неопределенная ссылка на `IMG_LoadTexture 'collect2.exe: error: ld вернул 1 статус выхода

В папке MinGW \ bin у меня есть SDL2_image.dll, а в папке MinGW \ lib у меня есть libSDL2_image.a и .dll.a, и .la SDL2 работает нормально, и я не понимаю, что может быть неправильным / отличаться от SDL_image в моем случае.

...