error LNK2019: 无法解析的外部符号 _stbi_load 使用stb_image.h库的错误

此错误在使用stb_image.h图片加载库时遇到

1>------ 已启动生成: 项目: OpenGL, 配置: Debug Win32 ------
1>ResourceManager.cpp
1>ResourceManager.obj : error LNK2019: 无法解析的外部符号 _stbi_load,该符号在函数 "private: static class Texture2D __cdecl ResourceManager::loadTextureFromFile(char const *,unsigned char)" (?loadTextureFromFile@ResourceManager@@CA?AVTexture2D@@PBDE@Z) 中被引用
1>ResourceManager.obj : error LNK2019: 无法解析的外部符号 _stbi_image_free,该符号在函数 "private: static class Texture2D __cdecl ResourceManager::loadTextureFromFile(char const *,unsigned char)" (?loadTextureFromFile@ResourceManager@@CA?AVTexture2D@@PBDE@Z) 中被引用
1>D:\18482\visual studio\source\repos\OpenGL\Debug\OpenGL.exe : fatal error LNK1120: 2 个无法解析的外部命令
1>已完成生成项目“OpenGL.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

解决:在include"stb_image.h"前加上#define STB_IMAGE_IMPLEMENTATION,通过定义STB_IMAGE_IMPLEMENTATION,预处理器会修改头文件,让其只包含相关的    函数定义源码,相当于把这个头文件变为一个 .cpp 文件(原stb_image.h库的教程给出,具体原因未知)

猜你喜欢

转载自www.cnblogs.com/hjd21/p/12452187.html