无法链接glew的解决办法-编译开源库出现: error LNK2001: 无法解析的外部符号

时间:2022-06-18 10:09:28

无法链接glew的解决办法-编译开源库出现: error LNK2001: 无法解析的外部符号

  参考官方配置指南:http://glew.sourceforge.net/install.html

1. 编译build开源库中,引入了gluw, 正常引入:.h, .lib .dll 文件后,出现下列错误

<span style="font-size:14px;">>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___glewMultiTexCoord1fARB
>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___glewMultiTexCoord2fARB
>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___wglewGetPbufferDCARB
>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___wglewCreatePbufferARB
>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___wglewChoosePixelFormatARB
>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___wglewBindTexImageARB
>gpu_util.obj : error LNK2001: 无法解析的外部符号 ___glewActiveTextureARB
>main.obj : error LNK2001: 无法解析的外部符号 ___glewActiveTextureARB
>main.obj : error LNK2019: 无法解析的外部符号 _glewGetString@,该符号在函数 _init 中被引用
>main.obj : error LNK2019: 无法解析的外部符号 _glewInit@,该符号在函数 _init 中被引用
>Release\gpu_sph.exe : fatal error LNK1120: 个无法解析的外部命令</span>

  我检查了自己的lib文件的链接还有附加库的目录都没有问题,后来在一个国外网站找到了解决的办法:

You have now set up the project to include the appropriate headers and build against the correct libraries. These particular instructions will treat GLEW and GLUT as "dynamically linked" libraries. This means that you will have to distribute the glut32.dll and glew32.dll files along with your program for users without GLUT and GLEW installed.

GLEW, 采用静态连接, 这样可以避免,将glew32.dll , glut32.dll动态库同程序一起发布。

GLEW gives you the option of "static linking," which allows you to avoid redistributing glew32.dll. To do this, #define GLEW_STATIC before the #include <GL/glew.h> line. Also choose to link against glew32s.lib instead of glew32.lib.

按照他的说法,我尝试了把glew32.lib改为glew32s.lib(前提,你要把glew32s.lib已经拷贝到了lib文件夹下面),还有要把链接器->常规里面的附加库的目录设为glew32s.lib所在的文件夹

点击调试,ok!!!

弄了一天,终于搞定了。

所以,增加一个方法

另一个方法:就是把glew32.lib改为glew32s.lib,把链接器->常规里面的附加库的目录设为glew.lib所在的文件夹,在#include <GL/glew.h>前面加上#define GLEW_STATIC