简体   繁体   English

Eclipse C ++ SDL_Image库不起作用

[英]eclipse c++ SDL_Image library not working

This is my code. 这是我的代码。

#ifndef LOADBMP_H_
#define LOADBMP_H_

#include "SDL2/SDL.h"
#include "res_path.h"
#include "SDL2/SDL_image.h"
SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren) 
{
    SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str()); <-- troublesome line
    if (texture == NULL)
    {
        logSDLError(std::cout, "LoadTexture");
    }
    return texture;
}

#endif /* LOADBMP_H_ */

When I try to compile, it gives me an error: undefined reference to `IMG_LoadTexture' I have properly installed the library. 当我尝试编译时,它给我一个错误:未正确引用“ IMG_LoadTexture”,我已经正确安装了该库。 What am I doing wrong? 我究竟做错了什么?

If you have correctly installed it, it looks like you haven't linked it properly. 如果安装正确,则好像没有正确链接。 You need to link the library in the same way that you would for SDL2 and SDL2_main. 您需要以与SDL2和SDL2_main相同的方式链接库。

For example in the image below you would add SDL2_image to it (this is Windows but same applies for other platforms on Eclipse) 例如,在下面的图像中,您将向其中添加SDL2_image(这是Windows,但对Eclipse上的其他平台也适用)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM