链接器错误:对符号'glOrtho'的未定义引用 [英] Linker error : undefined reference to symbol 'glOrtho'
本文介绍了链接器错误:对符号'glOrtho'的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Ubuntu 13.04(*mesa-common-dev freeglut3-dev*
)中安装了OpenGL软件包,并尝试运行示例程序.
I installed OpenGL packages in Ubuntu 13.04 ( *mesa-common-dev freeglut3-dev*
) and tried to run a sample program.
#include "GL/freeglut.h"
#include "GL/gl.h"
/* display function - code from:
http://fly.cc.fer.hr/~unreal/theredbook/chapter01.html
This is the actual usage of the OpenGL library.
The following code is the same for any platform */
void renderFunction()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
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();
}
/* Main method - main entry point of application
the freeglut library does the window creation work for us,
regardless of the platform. */
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("OpenGL - First window demo");
glutDisplayFunc(renderFunction);
glutMainLoop();
return 0;
}
但是,我遇到了这个错误,却不知道该怎么处理.
However, I encountered this error and don't know what to make of it.
ved@vedvals:~/Desktop/p1$ g++ p1.cpp -lglut
/usr/bin/ld: /tmp/ccgGdeR2.o: undefined reference to symbol 'glOrtho'
/usr/bin/ld: note: 'glOrtho' is defined in DSO /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 so try adding it to the linker command line
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
我看了
OpenGL hello.c无法使用CMake构建
因为错误类似,但我没有使用CMake
I had a look at
OpenGL hello.c fails to build using CMake
as the error is similar but I am not using CMake
我的代码是错误的还是需要包含/更改/调整某些设置?
IS my code wrong or do I need to include/change/tweak some settings?
我已将此站点转介用于安装和代码:
I referred this site for installation and code :
推荐答案
您需要链接OpenGL库:
You need to link the OpenGL library:
g++ p1.cpp -lglut -lGL
这篇关于链接器错误:对符号'glOrtho'的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文