| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 709 人关注过本帖
标题:求助 为什么 VC下OPENGL 控制台编程会出现如下错误!!
只看楼主 加入收藏
百惠在心
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-11-25
收藏
 问题点数:0 回复次数:7 
求助 为什么 VC下OPENGL 控制台编程会出现如下错误!!
/* Vertex array example by Nutty. (www.)
   Demonstrates the use of vertex arrays for defining geometric primitives.
   Using glut to hide the ugliness of windoze code.

   This source can be distributed freely.
   Nutty.    nutty@
*/
#include "stdlib.h"
#include "windows.h"
#include <GL/glut.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")

// The Initial size of our window
int window_width = 640;
int window_height = 480;

// Define our vertex structure.
// This holds the position of the vertices. Can also be used for
// anything that requires 3 float elements. i.e. colors.
typedef struct
{
    GLfloat x, y, z;

}Vertex3;

// Our constant. Number of faces per cube.
const GLuint NUMBER_FACES    =    6;
// This is a variable for rotating the cube.
GLfloat angle            =    0.0f;


// Our vertex array! Holds the points for each corner of the cube.
Vertex3 cube_verts[] = {
    {    -2.0f,    2.0f, 2.0f,    },    //Frontface top left.        0
    {     2.0f,    2.0f, 2.0f,    },    //Frontface top right.        1
    {     2.0f, -2.0f, 2.0f,    },    //Frontface bottom right.    2
    {   -2.0f, -2.0f, 2.0f, },  //Frontface bottom left.    3

    {    -2.0f,    2.0f, -2.0f, },    //backface top left.        4
    {     2.0f,    2.0f, -2.0f, },    //backface top right.        5
    {     2.0f, -2.0f, -2.0f, },    //backface bottom right.    6
    {   -2.0f, -2.0f, -2.0f, }    //backface bottom left        7
};

// This is an array of colors. Each color defined by 3 floats. Order will map
// directly to the cornder described in the above array.
Vertex3 vert_colors[] = {
    {    1.0f,    0.0f,   0.0f,    },   
    {    0.0f,    1.0f,   0.0f,    },
    {    0.0f,    0.0f,    1.0f,    },
    {    1.0f,    1.0f,    0.0f,    },

    {    1.0f,    0.0f,    1.0f,    },
    {    0.0f,    1.0f,    1.0f,    },
    {    0.0f,    0.0f,    0.0f,    },
    {    1.0f,    1.0f,    1.0f,    }
};

// These are the indexes into the above arrays to make our cube.
GLuint cube_indexes[NUMBER_FACES * 4] = {
    0, 3, 2, 1,                    //Frontface. In counter clockwise order.
    5, 6, 7, 4,                    //Backface.  In counter clockwise order.
    4, 0, 1, 5,                    //Top face.   
    3, 7, 6, 2,                    //Bottom face.
    4, 0, 3, 7,                    //Left face.
    1, 2, 6, 5,                    //Right face.

};



void Render(void)
{
   
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0f, 0.0f, -5.0f);        //Move the Cube 10 away from us!

    glRotatef(angle, 1.0f, 0.77f, 0.0f);        //Spin the cube in X and Y axis.

   
    //Enable the vertex and color arrays.
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
   
    //Tell gl, what our arrays look like! 3 floats per vertex, 0 packing, and their addresses.
    glVertexPointer(3, GL_FLOAT, 0, cube_verts);
    glColorPointer(3, GL_FLOAT, 0, vert_colors);

    //Do it! Draw quads. With 6 faces times 4 indexes per face.
    glDrawElements(GL_QUADS, NUMBER_FACES * 4, GL_UNSIGNED_INT, cube_indexes);
        
   
    glutSwapBuffers();
}

void Idle(void)
{   
   

    //Increase angle.
    angle += 0.4f;        

    if(angle >= 360.0f)
    {
        angle -= 360.0f;
    }

    //Re display.
    glutPostRedisplay ();   
}

void Resize(int width, int height)
{
    if(height == 0)
    {
        height = 1;
    }
     
    window_width = width;
    window_height = height;

   
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport(0, 0, window_width, window_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective (90, (float)window_width / (float)window_height, 1, 5000);

    glutPostRedisplay();
}

void Keyboard(unsigned char key, int x, int y)
{

    if(key == 27)    //If escape key.
    {
        exit(0);
    }
}

void Mouse(int button, int state, int x, int y)
{
}

void glInit(void)
{
    glEnable(GL_DEPTH_TEST);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glShadeModel(GL_SMOOTH);
}

void main(void)
{
    //Setup the window. RGB double buffered, with a depth buffer.
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(window_width, window_height);
    glutCreateWindow("Vertex Array Test - Esc quits");

    //Setup our callbacks.
    glutDisplayFunc(Render);
    glutReshapeFunc(Resize);
    glutIdleFunc(Idle);
    glutKeyboardFunc(Keyboard);
    glutMouseFunc(Mouse);

    glInit();
    glutMainLoop();
}
////////////////////////////////////////////////////////////

Build Log

--------------------Configuration: vertexarrays - Win32 Debug--------------------

Command Lines
Creating temporary file "C:\DOCUME~1\xiaolong\LOCALS~1\Temp\RSP23.tmp" with contents
[
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/vertexarrays.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"D:\新建文件夹 (3)\main.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\xiaolong\LOCALS~1\Temp\RSP23.tmp"
Creating temporary file "C:\DOCUME~1\xiaolong\LOCALS~1\Temp\RSP24.tmp" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/vertexarrays.pdb" /debug /machine:I386 /out:"Debug/vertexarrays.exe" /pdbtype:sept
".\Debug\main.obj"
]
Creating command line "link.exe @C:\DOCUME~1\xiaolong\LOCALS~1\Temp\RSP24.tmp"
Output Window
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol ___glutCreateWindowWithExit@8
Debug/vertexarrays.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.



Results
vertexarrays.exe - 2 error(s), 0 warning(s)


搜索更多相关主题的帖子: 控制台 
2011-03-23 15:59
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
无法解析的外部符号glutCreateWindowWithExit,有两个可能,第一个是你LINK的LIB库路径不正确,第二个是你的库版本不正确,总之是编译器无法找到这个函数的二进制代码,如果你能确定你的LINK路径设置正确的话,哪么可能是库的问题,网上说这个函数在 glut32.lib里,你在网上找找这个库,下载到LINK路径里试试看.
2011-03-25 21:10
百惠在心
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-11-25
收藏
得分:0 
谢谢
2011-03-31 18:33
百惠在心
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-11-25
收藏
得分:0 
可是我安装了glut32.lib 库文件了
2011-03-31 18:34
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
如果你确实安装了这个库,那么从前面的错误信息中看,编译器没有找到这个库文件。你总得告诉编译器你安在什么地方,基于这个想法,你思考一下如何让编译器知道这个库在哪儿
2011-04-12 22:48
百惠在心
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-11-25
收藏
得分:0 
可是VC++win32 框架下却能编程,还有MFC
2011-04-15 16:14
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
这就不清楚了。
有时候编译器会暗地里为你做一些事情,也就是说,也会不为你做一些事情而需要自己手动添加,如果是不同的编译环境这种情况是存在的。
而就楼主的问题,其根本原因是编译器在编译链接的时,无法找到___glutCreateWindowWithExit@8
符号的实现代码(即编译器知道有这个符号的存在,但找不到它定义的地方,对编译器来说就是有声明无定义,你可以个实验,声明一个函数但不写定义,然后调用这个函数,将会出现类似的错误),所以解决的途径是先要知道这个符号是属于哪个,有可能是CPP文件,也可能是LIB库,也可能是DLL,搞清楚它的定义在什么文件中后,需要做的就是让编译器知道这个文件的位置,使得它在链接时能够找到它。
2011-04-16 13:41
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
楼主可以在前面的错误信息中那堆LIB中找找看有没有glut32.lib,
这说明你没有把glut32.lib包含到工程中,包含一个LIB的方法就VC来说,可以在代码中包含,也可以在编译器的设置中包含。
2011-04-16 13:50
快速回复:求助 为什么 VC下OPENGL 控制台编程会出现如下错误!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016981 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved