C++ OpenGL GLut 编译问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5365441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenGL GLut compiling issues
提问by rich
hi im doing an openGL project but after downloading and installing the glut library files it still wont compile and i get 12 error C3861: identifier not found, any help would be great
嗨,我正在做一个 openGL 项目,但在下载并安装了 glut 库文件后,它仍然无法编译,我收到 12 错误 C3861:找不到标识符,任何帮助都会很棒
#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);
}
and my errors are
我的错误是
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
the glut32.dll file is in my system32 folder
glut32.dll 文件在我的 system32 文件夹中
my glut.h file is in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include
我的 glut.h 文件在 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include
and my glut.lib file is in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
我的 glut.lib 文件在 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
UPDATE added and now i have these errors
添加了更新,现在我有这些错误
error LNK2019: unresolved external symbol _glutMainLoop@0 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutReshapeFunc@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutKeyboardFunc@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutDisplayFunc@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutCreateWindow@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInitWindowPosition@8 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInitWindowSize@8 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInitDisplayMode@4 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol _glutInit@8 referenced in function _main
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function "void __cdecl keyboard(unsigned char,int,int)" (?keyboard@@YAXEHH@Z)
1>openGL.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "void __cdecl resize(int,int)" (?resize@@YAXHH@Z)
1>openGL.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "void __cdecl resize(int,int)" (?resize@@YAXHH@Z)
采纳答案by Mormegil
回答by Iranian_boy
This problem resulted from wrong .lib linking.
这个问题是由错误的 .lib 链接引起的。
In Project's properites, choose: Configuration properties -> linker -> input
在 Project 的属性中,选择:配置属性 -> 链接器 -> 输入
in the right column choose: additional dependencies, add following libraries to the list, seperated by semi colon: opengl32.lib ; glut32.lib ; glu32.lib ;
在右栏中选择:附加依赖项,将以下库添加到列表中,以分号分隔: opengl32.lib ;glut32.lib ; glu32.lib ;
This will solve the problem.
这将解决问题。
回答by Joshua 'Cuppers' Whittle
Only use #include <glut.h>
只使用 #include <glut.h>
GLUT contains all the gl.h functions anyway. just make sure that in the project settings you set all the dependancies for glut32.lib, openGL32.lib etc.
无论如何,GLUT 包含所有 gl.h 函数。只需确保在项目设置中为 glut32.lib、openGL32.lib 等设置了所有依赖项。
回答by Raino sommer
i created a video on how to set up glfw. it was 20 minutes of pain, but finally got it to work. http://www.youtube.com/watch?v=dpsC4kP2ME0visual studio 2010 seems to be very sensitive to configuration, make sure configuration is set to "all configurations".
我创建了一个关于如何设置 glfw 的视频。痛苦了 20 分钟,但终于让它起作用了。 http://www.youtube.com/watch?v=dpsC4kP2ME0Visual Studio 2010 似乎对配置非常敏感,请确保将配置设置为“所有配置”。