安装完了之后用于测试是否成功了的例子:
//te.c
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5,-0.5);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();
glFlush();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("Hello,world!");
glutDisplayFunc(display);
glutMainLoop();
}
编译命令:
g++ te.c -o te -g -lglut -lm
我所遇到的问题
/usr/bin/ld: note: 'glVertex2f' is defined in DSO /lib64/libGL.so.1 so try adding it to the linker command line
/lib64/libGL.so.1: could not read symbols: 无效的操作
collect2: 错误:ld 返回 1
按照提示附加链接就好啦
g++ te.c -o te -g -lglut -lm /lib64/libGL.so.1
运行后的界面如图: