【问题标题】:stb_image.h in Visual Studio - unresolved external symbolVisual Studio 中的 stb_image.h - 未解析的外部符号
【发布时间】:2014-07-28 02:06:58
【问题描述】:

我已下载 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

【问题讨论】:

    标签: c++ visual-studio-2012 compiler-errors


    【解决方案1】:

    答案就在stb_image.h上方:

    这样做:

      #define STB_IMAGE_IMPLEMENTATION    
    

    在您将此文件包含在一个 C 或 C++ 文件中以创建实现之前。
    即它应该是这样的:

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

    没有这个定义,你会得到关于未解析的外部符号的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 2011-10-02
      • 2021-08-02
      • 2015-05-11
      相关资源
      最近更新 更多