Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue loading images with stb_image [duplicate]

Tags:

c++

opengl

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'
like image 729
Roy Varon Avatar asked Jun 18 '17 17:06

Roy Varon


1 Answers

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.

like image 62
D.J. Klomp Avatar answered Oct 24 '22 03:10

D.J. Klomp