如何链接到OpenGL?

时间:2012-02-17 16:39:57

标签: c++ c visual-studio-2008 opengl

我已经安装了VS 2008,我已经复制了这些库:

  • opengl32.lib
  • glu32.lib
  • glut32.lib

进入库文件夹,并将相应的头文件放入include文件夹。

我还在项目属性中添加了这些文件 - > Linker->输入 - >其他依赖项:

  • Opengl32.lib
  • glu32.lib
  • glut32.lib

我是否必须使用引号添加它们?像这样:"Opengl32.lib" "glu32.lib" "glut32.lib"

我创建了以下程序,它只显示一个窗口:

#include<GL/glut.h>

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glFlush();
}

void main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(500,500);
    glutCreateWindow("3D gasket");
    glutDisplayFunc(display);
    glClearColor(1.0,1.0,1.0,1.0);
    glutMainLoop();
}

但是链接失败了以下输出:

1>------ Build started: Project: vs, Configuration: Debug Win32 ------
1>Linking...
1>pr1.obj : error LNK2019: unresolved external symbol _glFlush referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>pr1.obj : error LNK2019: unresolved external symbol _glLoadIdentity referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>pr1.obj : error LNK2019: unresolved external symbol _glClear referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>pr1.obj : error LNK2019: unresolved external symbol _glutMainLoop referenced in function _main
1>pr1.obj : error LNK2019: unresolved external symbol _glClearColor referenced in function _main
1>pr1.obj : error LNK2019: unresolved external symbol _glutDisplayFunc referenced in function _main
1>pr1.obj : error LNK2019: unresolved external symbol _glutCreateWindow referenced in function _main
1>pr1.obj : error LNK2019: unresolved external symbol _glutInitWindowSize referenced in function _main
1>pr1.obj : error LNK2019: unresolved external symbol _glutInitDisplayMode referenced in function _main
1>pr1.obj : error LNK2019: unresolved external symbol _glutInit referenced in function _main
1>D:\Program Files\Microsoft Visual Studio 9.0\projects\vs\Debug\vs.exe : fatal error LNK1120: 10 unresolved externals
1>Build log was saved at "file://d:\Program Files\Microsoft Visual Studio 9.0\projects\vs\vs\Debug\BuildLog.htm"
1>vs - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我不知道造成这些问题的原因是什么,谁能详细解释这些消息?以及如何解决它们?

1 个答案:

答案 0 :(得分:3)

请参阅以下NeHe教程:

http://nehe.gamedev.net/tutorial/creating_an_opengl_window_%28win32%29/13001/

确保在任何OpenGL标头之前包含windows.h,并且还包括gl\GL.h。使用glaux时教程有点过时,但对于初次使用的用户来说仍然是可靠的,后来的文章删除了glaux依赖项。

或者这个灯塔3D课程:

http://www.lighthouse3d.com/tutorials/glut-tutorial/setup-basics/