CodeBlocks新建GLUT 项目,测试程序出现 函数 undefined reference to ‘imp__glViewport’错误
程序员文章站
2022-06-22 16:17:18
...
codeBlocks配置好opengl 后新建一个 GLUT工程,会自动在main函数下生产一个测试程序。
如果出现编译错误,函数未定义
||=== Build: Debug in test3 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `resize':|
undefined reference to `_imp__glViewport'|
undefined reference to `_imp__glMatrixMode'|
undefined reference to `_imp__glLoadIdentity'|
undefined reference to `_imp__glFrustum'|
undefined reference to `_imp__glMatrixMode'|
undefined reference to `_imp__glLoadIdentity'|
解决办法,在代码第一行,加上宏定义 #define _STDCALL_SUPPORTED,代码前几行如下图
#define _STDCALL_SUPPORTED
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
static int slices = 16;
static int stacks = 16;
/* GLUT callback Handlers */
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
重新编译运行,结果如下图