0

so I was following this tutorial, and everything was going all smooth and dandy, until I encountered a problem, namely that I couldn't load a .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;
}

When I try to compile the code (in Code::Blocks) it gives me the error of

Undefined reference to "IMG_LoadTexture"

Well, I tried to change IMG_LoadTexture(renderer, "grass.bmp"); to IMG_LoadTexture(renderer, "/the/full/path/of/grass.bmp");but this didn't work either. Same error. Have I written something wrong, or missed some part? Also, grass.bmp is in the same folder as main.cpp (the code above).

genpfault
  • 51,148
  • 11
  • 85
  • 139
Kimple
  • 117
  • 1
  • 9
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – genpfault May 17 '16 at 16:27

1 Answers1

0

The error here says that you have declared a function but have not defined it - undefined reference.

Most probably it happened because you forgot to link against library SDL_image to which function IMG_LoadTexture belongs.

Community
  • 1
  • 1
Teivaz
  • 5,462
  • 4
  • 37
  • 75