我在Ubuntu 13.04(*mesa-common-dev freeglut3-dev*
)中安裝了OpenGL軟件包,並試圖運行一個示例程序。鏈接錯誤:未定義引用符號'glOrtho'
#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;
}
但是,我遇到了這個錯誤,不知道該怎麼做。
[email protected]:~/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 fails to build using CMake
的錯誤是類似的,但我不使用CMake的
是我的代碼錯了或者我需要包括/變更/調整一些設置?
我提到這個網站安裝代碼:
Setting up an OpenGL development environment in Ubuntu Linux
我是新來的opengl編程,是否有任何方法來自動化過程,或者我必須總是添加上面指定的所有我的opengl程序的鏈接器參數?我已經引用了與用於初始化我的系統的opengl代碼項目相同的鏈接,並使用ubuntu 13.04。 – meteors
在Linux中,我不得不添加「-lGLU」。 – user1754322