SDL_Image无法正常运行。 “未解析的外部符号_IMG_LoadTexture”

时间:2013-09-21 04:13:00

标签: c++ image sdl sdl-2

我一直试图修复这个特定的SDL错误一段时间,奇怪的是没有通过搜索找到同样的错误。

以下是Visual Studio错误输出:

Error   1   error LNK2019: unresolved external symbol _IMG_LoadTexture referenced in function "struct SDL_Texture * __cdecl LoadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadImage@@YAPAUSDL_Texture@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)    C:\Users\DemonicSmokingJacket\Documents\Visual Studio 2012\Projects\ShitHappens\ShitHappens\main.obj    ShitHappens

以下是代码:

#include <SDL.h>
#include <SDL_image.h>
#include <string>

const int screen_x = 640;
const int screen_y = 480;

SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;

using namespace std;

SDL_Texture *LoadImage(string file)
{

    //Initialized variables for texture.
    SDL_Texture *texture = nullptr;

    //Load image.
    texture = IMG_LoadTexture(renderer, file.c_str());
    return texture;
}

void ApplySurface(int x, int y, SDL_Texture *texture, SDL_Renderer *second_renderer)
{
    //Initialize variables and set x and y axis.
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;
    SDL_QueryTexture(texture, NULL, NULL, &pos.w, &pos.h);
    SDL_RenderCopy(second_renderer, texture, NULL, &pos);
}

int main(int argc, char* argv[])
{
    //Initialize variables limited to function 'main'.
    int bW, bH, iW, iH, x, y;
    SDL_Texture *background = nullptr, *image = nullptr;

    //Initialize all of SDL's features; an SDL window and make the window rendable.
    SDL_Init(SDL_INIT_EVERYTHING);
    window = SDL_CreateWindow("Shit Happens", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_x, screen_y, SDL_WINDOW_SHOWN);
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

    //Load background images from 'LoadImage' function.
    background = LoadImage("background.png");
    image = LoadImage("image.png");

    //Clear Render 'renderer'.
    SDL_RenderClear(renderer);

    //Display and tile background image. "background.bmp"
    SDL_QueryTexture(background, NULL, NULL, &bW, &bH);
    ApplySurface(bW, bH, background, renderer);
    ApplySurface(bW, 0, background, renderer);
    ApplySurface(0, bH, background, renderer);
    ApplySurface(0, 0, background, renderer);

    //Display front image. "image.bmp"
    SDL_QueryTexture(image, NULL, NULL, &iW, &iH);
    x = screen_x / 2 - iW / 2;
    y = screen_y / 2 - iH / 2;

    //Apply changes to renderer.
    ApplySurface (x, y, image, renderer);

    //Apply renderer to screen.
    SDL_RenderPresent(renderer);
    SDL_Delay(2000);

    //Destroy the SDL Textures (images); the SDL Renderer and the SDL window.  
    SDL_DestroyTexture(background);
    SDL_DestroyTexture(image);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);

    //Quit SDL.
    SDL_Quit();

    return 0;

}

非常感谢你的时间,希望这会对其他用户有所帮助。 此致 (DamnitIForgotMyName)

1 个答案:

答案 0 :(得分:1)

感谢自己,我得出了一个结论。问题是我没有从http://www.libsdl.org/projects/SDL_image/下载最新版本的SDL_Image,它包含函数IMG_LoadTexture

再次感谢自己。