gpt4 book ai didi

c++ - Visual Studio 中的 stb_image.h - 未解析的外部符号

转载 作者:太空宇宙 更新时间:2023-11-04 15:03:23 32 4
gpt4 key购买 nike

我已经下载了 stb_image.h ( https://github.com/nothings/stb ) 并包含在我想使用它的 .cpp 文件中。

然后我使用函数加载图像

image_data = stbi_load(fileNames[i], &image_width, &image_height, &image_pixel_components, 0);

当我尝试在 Visual Studio 中运行代码时出现错误:

Error   3   error LNK2019: unresolved external symbol _stbi_load referenced in function "public: bool __thiscall CubemapTexture::Load(void)" (?Load@CubemapTexture@@QAE_NXZ)    ...\CubemapTexture.obj

Error 40 error LNK2001: unresolved external symbol _stbi_load ...\Texture.obj

最佳答案

答案就在stb_image.h 的顶部:

Do this:

  #define STB_IMAGE_IMPLEMENTATION    

before you include this file in one C or C++ file to create the implementation.
i.e. it should look like this:

#include ....
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

如果没有这个定义,您将收到有关未解析的外部符号的错误。

关于c++ - Visual Studio 中的 stb_image.h - 未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088002/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com