ho installato i pacchetti OpenGL in Ubuntu 13.04 (*mesa-common-dev freeglut3-dev*
) e ho cercato di eseguire un programma di esempio.errore del linker: undefined reference to simbolo '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;
}
Tuttavia, ho riscontrato questo errore e non so cosa farmene.
[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
ho dato un'occhiata a
OpenGL hello.c fails to build using CMake
come l'errore è simile, ma non sto usando CMake
è il mio codice sbagliato o ho bisogno di inserire/modificare/modificare alcune impostazioni?
ho fatto riferimento questo sito per l'installazione e il codice:
Setting up an OpenGL development environment in Ubuntu Linux
Sono nuovo di programmazione OpenGL, è Esiste un metodo per automatizzare il processo o devo aggiungere sempre i parametri linker come specificato in precedenza per tutti i miei programmi OpenGL? Ho fatto riferimento allo stesso link dei codeproject per l'inizializzazione del mio sistema per opengl e sto usando ubuntu 13.04. – meteors
In Linux ho dovuto aggiungere "-lGLU" in aggiunta a quelli. – user1754322