This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?

(36个答案)


3年前关闭。




我想使用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'

最佳答案

您可能应该在包含之前在代码中添加:#define STB_IMAGE_IMPLEMENTATION。在头文件的第一行中建议这样做。

关于c++ - 使用stb_image加载图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44617665/

10-10 20:48