静态链接库时链接器出现错误 [英] Linker error with glew when library is statically linked

查看:154
本文介绍了静态链接库时链接器出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Visual Studio 2012中构建一个opengl项目.我想静态地包含glew库,因此我从源代码构建了glew库,并将生成的glew32sd.lib复制到了我的lib目录.我将此库路径提供给Visual Studio,并将"glew32sd.lib"添加到VS中的其他依赖项中.

I am trying to build an opengl project in Visual Studio 2012. I wanted to statically include glew library, so I built it from source and copied the generated glew32sd.lib to my lib directory. I gave this lib path to Visual Studio and put "glew32sd.lib" to my additional dependencies in VS.

现在,当我在main.cpp中编译示例代码时:

Now when I compile a sample code in main.cpp:

#define GLEW_STATIC
#include<GL/glew.h>
int main(){
    glewInit();
    return 0;
}

我收到以下错误:

1>  main.cpp
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function _glewGetExtension@4
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__wglGetCurrentDC@0 referenced in function _wglewInit@0
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _wglewInit@0
1>C:\Projects\OpenGL\opengl\Debug\opengl.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

根据我的理解,此错误应该是因为编译器找不到函数调用的定义.

In my understanding, this error should be because compiler could not find the definitions for the function call.

以下是一些相关的快照: 我的项目的库依赖项

Here are a few relevant snapshots: The Library dependencies of my project

通往libs的路径

为什么会出现此错误?我尝试重建解决方案,但这也无济于事.任何建议都会有所帮助.

Why could this error be coming? I tried rebuilding the solution but that didn't help either. Any suggestion would be helpful.

推荐答案

链接器设置中存在两个问题:

You have two problems in the linker settings:

  • 您可以链接到glew的静态链接版本或动态链接的版本,但不能两者同时链接.因此,如果要静态链接,请从其他依赖项中删除glew32d.lib(或在发布模式下为glew32.lib).

  • You can link against the statically linked version of glew or the dynamically linked one, but never against both. So if you want glew statically linked remove glew32d.lib (or glew32.lib in release mode) from the additional dependencies.

Glew还需要您再次链接opengl库.将OpenGL32.lib添加到其他依赖项中.

Glew requires you to also link agains the opengl library. Add OpenGL32.lib to the additional dependencies.

这篇关于静态链接库时链接器出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆