在尝试在Eclipse上编译c ++ glut项目时,我得到了对所有OpenGL代码的“未定义引用”错误。
操作系统:Xubuntu 16.04 64位
Eclipse版本:NEON.2
在Eclipse上,我通过转到项目属性然后转到“C / C ++ Build”>>来链接库。设置>> Cross GCC Compiler>>包括。然后是“添加...”按钮,输入过剩。
c ++ glut例子:
#include <GL/glut.h>
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv) {
// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Lighthouse3D - GLUT Tutorial");
// register callbacks
glutDisplayFunc(renderScene);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}
终端上的错误:g++ main.cpp -o main -lglut
enter cod/usr/bin/ld: /tmp/cc4XI1YG.o: undefined reference to symbol 'glVertex3f'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
在Eclipse中,错误是: