所以我正在关注this教程,一切都顺利,花花公子,直到遇到问题,即我无法加载.bmp。
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdio.h>
#include <iostream>
#include <SDL2/SDL_main.h>
using namespace std;
int main(int argc, char* argv[]) {
bool quit = false;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window;
window = SDL_CreateWindow("window", 100, 100, 1280, 720, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if(window == NULL){
cout << "Disn't work, here is why: " << SDL_GetError()<< endl;
return 0;
}
SDL_Renderer* renderer = NULL;
renderer= SDL_CreateRenderer(window, -1 ,SDL_RENDERER_ACCELERATED);
SDL_Event* mainEvent = new SDL_Event();
SDL_Texture* grass_image = NULL;
grass_image = IMG_LoadTexture(renderer, "grass.bmp");
SDL_Rect grass_rect;
grass_rect.x = 10;
grass_rect.y = 50;
grass_rect.w = 250;
grass_rect.h = 250;
while(!quit && mainEvent->type != SDL_QUIT){
SDL_PollEvent(mainEvent);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, grass_image, NULL, &grass_rect);
SDL_RenderPresent(renderer);
}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;
return 0;
}
当我尝试编译代码时(在Code :: Blocks中)它给出了错误
对&#34; IMG_LoadTexture&#34;
的未定义引用
好吧,我尝试将IMG_LoadTexture(renderer, "grass.bmp");
更改为IMG_LoadTexture(renderer, "/the/full/path/of/grass.bmp");
,但这也无效。同样的错误。我写错了什么,或错过了某些部分?另外,grass.bmp与main.cpp在同一个文件夹中(上面的代码)。
答案 0 :(得分:0)
此处的错误表示您已声明了一个函数但未定义它 - undefined reference。
很可能是因为您忘记链接到IMG_LoadTexture
所属的函数库SDL_image。