设置 OpenGL - 它不起作用

Setting up OpenGL - it won't work

本文关键字:不起作用 OpenGL 设置      更新时间:2023-10-16

我刚买了一台windows 8 64位的笔记本电脑,我用的是Visual Studio 2012。我做了安装3d party lib的常规程序,就像我在以前的pc上安装它们一样:

  1. 下载免费eglut, glfw, glut, sdl
  2. 复制头文件到"C:Program Files (x86)Microsoft Visual Studio 11.0VCinclude"
  3. 将库复制到"C:Program Files (x86)Microsoft Visual Studio 11.0VClib"
  4. 将dll拷贝到"C:WindowsSysWOW64"

然后我下载了我在另一台电脑上开发的项目(如果这很重要的话,是在windows 8 32位下开发的),它无法编译。编译器抛出了以下链接错误:

Error 1 error LNK2001: unresolved external symbol __imp__glDrawArrays@12  - about 50 of these 
Error 63 error LNK2019: unresolved external symbol __imp__glClear@4 - again about 50 of these

这个项目在我的旧电脑上运行得很好。

我试着做一个简单的新项目:http://pastebin.com/GfEieL6f

链接以下库(属性->链接器->输入->附加依赖项)

opengl32.lib
glut32.lib
glu32.lib

仍然无法编译,同样的链接错误:

Error 1 error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 2 error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 3 error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _main P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 4 error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 5 error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 6 error LNK2019: unresolved external symbol __imp__glFlush@0 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 7 error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function _main P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 8 error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 9 error LNK2019: unresolved external symbol __imp__glOrtho@48 referenced in function _main P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 10 error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj
Error 11 error LNK2019: unresolved external symbol __imp__glVertex3iv@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:OpenGL_SetupOpenGL_Setupopengl_setup.obj

我不知道我是否遗漏了什么,你能给我一些建议吗?

p:我设法修复了简单的程序并运行它,但是我不能运行我的旧项目。也许是因为平台的改变?我该怎么修理它?
  1. 不要在编译器lib目录下添加文件。在项目中添加另一个库搜索路径。

  2. 您可能下载了与vc++ 2012和您的项目构建设置不兼容的库文件。在本机代码中,不能混合使用x86、x64等。静态库需要匹配你的项目,而不是你的操作系统。而且微软还改变/扩展了库文件格式,以及库使用的运行时库组件,所以你真的应该得到一个为你的vc++版本设计的库文件。