8

I want to load images using stb_image. I downloaded stb_image.h from https://github.com/nothings/stb. When I run the code:

string file="image.png";
int width,height,components;

unsigned char *imageData = stbi_load(file.c_str(),
        &width, &height, &components, STBI_rgb_alpha);

i get the following errors:

Main.cpp:(.text+0xa14): undefined reference to `stbi_load'
Main.cpp:(.text+0xb74): undefined reference to `stbi_image_free'
Roy Varon
  • 536
  • 2
  • 5
  • 14

1 Answers1

29

You probably should add: #define STB_IMAGE_IMPLEMENTATION to your code before the include. This is suggested in one of the first lines of the header file.

BDL
  • 21,052
  • 22
  • 49
  • 55
D.J. Klomp
  • 2,429
  • 1
  • 15
  • 30