使用stb_image发出加载图像的问题

时间:2017-06-18 17:25:48

标签: c++ opengl

我想使用stb_image加载图片。我从https://github.com/nothings/stb下载了stb_image.h。当我运行代码时:

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

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

我收到以下错误:

Main.cpp:(.text+0xa14): undefined reference to `stbi_load'
Main.cpp:(.text+0xb74): undefined reference to `stbi_image_free'

1 个答案:

答案 0 :(得分:10)

您可能应该在include之前为代码添加#define STB_IMAGE_IMPLEMENTATION。建议在头文件的第一行中使用。

相关问题