OpenGL初学者经常遇到的编译错误undefined reference to
(2012-07-17 10:07:01)
标签:
杂谈 |
分类: 计算机图形学-OpenGL |
I.
出现
[Linker error] undefined reference to `_imp____glutInitWithExit@12'
[Linker error] undefined reference to `_imp____glutCreateWindowWithExit
[Linker error] undefined reference to `_imp____glutCreateMenuWithExit@8'
[Linker error] undefined reference to `_imp__glutInitDisplayMode@4'
[Linker error] undefined reference to `_imp__glutInitWindowSize@8'
[Linker error] undefined reference to `_imp__glutInitWindowPosition@8'
[Linker error] undefined reference to `_imp__glutDisplayFunc@4'
[Linker error] undefined reference to `_imp__glutMainLoop@0'
等错误
原因如下:
Note that the __glut*WithExit routines should NEVER be called
directly.
To avoid the atexit workaround, #define
GLUT_DISABLE_ATEXIT_HACK.
#define GLUT_DISABLE_ATEXIT_HACK必须紧紧跟在#include <GL/glut.h>前
II.
在加上#define GLUT_DISABLE_ATEXIT_HACK后也会可能出现下述问题
这是由于没有正确选择project或者单纯打开一个.cpp或.c文件造成的
由于我在遇到这个问题时使用的是Dev-C++,所以就以Dev-C++为例
在安装过glut后,创建Project时在Multimedia选项中会多出一个glut选项,只有选择这个glut project才不会遇到上述两个问题
III.
以Dev-C++为例,有时linker中的顺序是很重要的
必须按照以下顺序:
-lglut32
-lopengl32
-lglu32
-lgdi32
-lwinmm
问题解决~~