2011-03-19 47 views
3

喜即時通訊做一個OpenGL項目,但是下載和安裝glut庫文件,它仍然不會編譯,我得到12錯誤C3861後:未找到標識,任何幫助將是巨大的OpenGL的過剩編制問題

#include <windows.h> 
#include <gl/gl.h> 

void init(void); 
void display(void); 
void keyboard(unsigned char, int, int); 
void resize(int, int); 

int is_depth; 

int main(int argc, char **argv) 
{ 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 
    glutInitWindowSize(600, 600); 
    glutInitWindowPosition(40, 40); 
    glutCreateWindow("3D World"); 
    init(); 
    glutDisplayFunc(display); 
    glutKeyboardFunc(keyboard); 
    glutReshapeFunc(resize); 

    glutMainLoop(); 

    return 0; 

} 

void init(void) 
{ 
    glClearColor(0.0, 0.0, 0.0, 0.0); 
    glEnable(GL_DEPTH_TEST); 
    is_depth = 1; 
    glMatrixMode(GL_MODELVIEW); 

} 

void display(void) 
{ 
    if (is_depth) 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    else 
     glClear(GL_COLOR_BUFFER_BIT); 

    glBegin(GL_QUADS); 
     glColor3f(0.2f, 0.2f, 0.2f); 
     glVertex3f(-100.0, 0.0, -100.0); 
     glColor3f(0.4f, 0.4f, 0.4f); 
     glVertex3f(-100.0, 0.0, 100.0); 
     glColor3f(0.6f, 0.6f, 0.6f); 
     glVertex3f(100.0, 0.0, 100.0); 
     glColor3f(0.8f, 0.8f, 0.8f); 
      glVertex3f(100.0, 0.0, -100.0);  
    glEnd(); 

} 

void keyboard(unsigned char key, int x, int y) 
{ 
    switch (key) 
    { 
    case 'a': 
     glTranslatef(5.0, 0.0, 0.0); 
     break; 

    case 'd': 
     glTranslatef(-5.0, 0.0, 0.0); 
     break; 

    case 's': 
     glTranslatef(0.0, 0.0, -5.0); 
     break; 

    case 'w': 
     glTranslatef(0.0, 0.0, 5.0); 
     break; 

    } 

    display(); 

} 

void resize(int width, int height) 
{ 
    if(height == 0) height = 1; 

    glMatrixMode(GL_PROJECTION); 

    glLoadIdentity(); 

    gluPerspective(45.0, width/height, 1.0, 400.0); 

    glTranslatef(0.0, -5.0, -150.0); 

    glMatrixMode(GL_MODELVIEW); 
} 

和我的錯誤是

1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(17) : error C3861: 'glutInit': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(18) : error C2065: 'GLUT_DOUBLE' : undeclared identifier 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(18) : error C2065: 'GLUT_RGB' : undeclared identifier 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(18) : error C3861: 'glutInitDisplayMode': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(19) : error C3861: 'glutInitWindowSize': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(20) : error C3861: 'glutInitWindowPosition': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(21) : error C3861: 'glutCreateWindow': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(23) : error C3861: 'glutDisplayFunc': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(24) : error C3861: 'glutKeyboardFunc': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(25) : error C3861: 'glutReshapeFunc': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(27) : error C3861: 'glutMainLoop': identifier not found 
1>c:\users\riche\documents\visual studio 2008\projects\opengl\opengl\opengl.cpp(97) : error C3861: 'gluPerspective': identifier not found 

的要將glut32.dll文件是在我的system32文件夾下

我glut.h文件位於C:\ Program Files文件(x86)的\微軟的Visual Studio 9.0 \ VC \ INC路得

和我glut.lib文件位於C:\ Program Files文件(x86)的\微軟的Visual Studio的lib

UPDATE加入9.0 \ VC \ ,現在我有這些錯誤

error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl init(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl init(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl init(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl display(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl display(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl display(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl display(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl display(void)" ([email protected]@YAXXZ) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl keyboard(unsigned char,int,int)" ([email protected]@[email protected]) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl resize(int,int)" ([email protected]@[email protected]) 
1>openGL.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl resize(int,int)" ([email protected]@[email protected]) 
+0

整個一步一步的過程中,以防其他人有同樣的問題在這裏: http://stackoverflow.com/a/8985903/744859 – 2012-01-24 14:24:03

回答

1

您包含gl.h,但由於您使用的是GLUT,這不包含在OpenGL中,因此您還需要#include <glut.h>

+0

我不認爲你應該包括gl.h之前glut.h,不知道是否它或glu,但我記得其中一個不正確與它 – deek0146 2011-03-19 22:53:32

+0

沒有工作得到更多的erros – rich 2011-03-19 22:54:45

+0

您修復了原來的錯誤,現在你沒有連接glut.lib – deek0146 2011-03-19 22:56:03

3

僅使用#include <glut.h>

GLUT包含了所有的gl.h功能反正。只需確保在項目設置中設置了glut32.lib,openGL32.lib等所有依賴項。

4

此問題源於錯誤的.lib鏈接。

在項目的性質在選擇: 配置屬性 - >連接 - >輸入

在右列中進行選擇:額外的依賴, 添加下列庫到列表中,由分號分隔: opengl32.lib; glut32.lib; glu32.lib;

這將解決問題。

-1

我創建了一個關於如何設置glfw的視頻。這是20分鐘的痛苦,但最終得到它的工作。 http://www.youtube.com/watch?v=dpsC4kP2ME0 visual studio 2010似乎對配置非常敏感, 確保配置設置爲「所有配置」。