【问题标题】:OpenGL Linking problemsOpenGL链接问题
【发布时间】:2016-01-01 13:23:06
【问题描述】:

我正在尝试用 c++ 构建一个 OpenGL 应用程序。我使用 glew 和 glfw 库。现在我想创建一些纹理,但现在它说:

1>model.obj : error LNK2019: unresolved external symbol __imp_glBindTexture referenced in function "public: void __cdecl Texture::Bind(unsigned int)" (?Bind@Texture@@QEAAXI@Z)
1>model.obj : error LNK2019: unresolved external symbol __imp_glGenTextures referenced in function "public: bool __cdecl Texture::Load(void)" (?Load@Texture@@QEAA_NXZ)
1>model.obj : error LNK2019: unresolved external symbol __imp_glTexImage2D referenced in function "public: bool __cdecl Texture::Load(void)" (?Load@Texture@@QEAA_NXZ)
1>model.obj : error LNK2019: unresolved external symbol __imp_glTexParameterf referenced in function "public: bool __cdecl Texture::Load(void)" (?Load@Texture@@QEAA_NXZ)
1>C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\lib\magickdb.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
1>C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\lib\magickrl.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
1>C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\x64\Debug\OpenGLTest3.exe : fatal error LNK1120: 16 unresolved externals

到目前为止一切正常(glGenVertexArrays()、glDrawArrays() 等),只有纹理函数(glGenTextures()、glBindTexture() 等)不起作用。 Linker 是这样设置的:glew32.lib;glfw3.lib;assimp.lib;devil.lib;magickdb.lib;magickrl.lib;%(AdditionalDependencies)

VC 包含目录: C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\include;$(IncludePath) VC 库目录: C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\lib;$(LibraryPath)

【问题讨论】:

  • 你缺少 opengl32.lib 吗?
  • @BDL 我认为 opengl32.lib 仅适用于已弃用的 OpenGL1.1 的东西。我这边的误会/_\。如果您将其发布为答案,我会接受它

标签: c++ opengl linker visual-studio-2015


【解决方案1】:

直到 OpenGL 1.1 的所有函数都直接在 opengl32.lib 库中实现。所有其他功能都可以通过扩展获得,并且必须手动加载(或使用 glew 之类的库)。

在您的情况下,您缺少再次链接opengl32.lib

【讨论】:

    【解决方案2】:

    这里发生了一些事情... OpenGL 随 Windows 一起提供,但只有 OpenGL 1.1 和 opengl32.lib。因此,所有后续 OpenGL 版本都需要一个扩展库,例如 glew。现在,freeglut 包含 opengl32.lib 但 glew 不包含,因此如果您使用 glew,则必须自己包含 opengl32.lib。在 Visual Studio 下,右键单击您的项目(粗体),然后在 Properties/Linker/Input 中添加 openg32.lib。无需在 C/C++/General 或 Linker/General 中的 Properties 中添加任何其他目录 - opengl32.lib 随 Windows 一起提供,Visual Studio 知道在哪里可以找到它,但仍需要被告知链接它!最后,将相应的动态库,如freeglut.dll或glew32.dll复制到你的可执行文件所在的Visual Studio Debug目录下。

    【讨论】:

    • GLUT/freeglut 不是扩展加载器。他们管理窗口、上下文和事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    • 2010-12-20
    • 2011-01-23
    • 2013-12-13
    相关资源
    最近更新 更多