ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}
Now when i compile the program i get the errors listed below :
[root@kkp opengl]# gcc g.cc
/tmp/ccAHnH5T.o(.text+0xf): In function `display()':
: undefined reference to `glClear'
/tmp/ccAHnH5T.o(.text+0x29): In function `display()':
: undefined reference to `glColor3f'
/tmp/ccAHnH5T.o(.text+0x36): In function `display()':
: undefined reference to `glBegin'
/tmp/ccAHnH5T.o(.text+0x4d): In function `display()':
: undefined reference to `glVertex3f'
/tmp/ccAHnH5T.o(.text+0x64): In function `display()':
: undefined reference to `glVertex3f'
/tmp/ccAHnH5T.o(.text+0x7b): In function `display()':
: undefined reference to `glVertex3f'
/tmp/ccAHnH5T.o(.text+0x92): In function `display()':
: undefined reference to `glVertex3f'
/tmp/ccAHnH5T.o(.text+0x9a): In function `display()':
: undefined reference to `glEnd'
/tmp/ccAHnH5T.o(.text+0x9f): In function `display()':
: undefined reference to `glFlush'
/tmp/ccAHnH5T.o(.text+0xb5): In function `init()':
: undefined reference to `glClearColor'
/tmp/ccAHnH5T.o(.text+0xc5): In function `init()':
: undefined reference to `glMatrixMode'
/tmp/ccAHnH5T.o(.text+0xcd): In function `init()':
: undefined reference to `glLoadIdentity'
/tmp/ccAHnH5T.o(.text+0xf6): In function `init()':
: undefined reference to `glOrtho'
/tmp/ccAHnH5T.o(.text+0x11b): In function `main':
: undefined reference to `glutInit'
/tmp/ccAHnH5T.o(.text+0x128): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/ccAHnH5T.o(.text+0x13d): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/ccAHnH5T.o(.text+0x14c): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/ccAHnH5T.o(.text+0x15c): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/ccAHnH5T.o(.text+0x171): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/ccAHnH5T.o(.text+0x179): In function `main':
: undefined reference to `glutMainLoop'
/tmp/ccAHnH5T.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
i also tried using :
#gcc g.cc -lglut -lGL
it gives me :
cc1plus: warning: `lut': unknown or unsupported -g option
/tmp/cc04tCtz.o(.text+0x11b): In function `main':
: undefined reference to `glutInit'
/tmp/cc04tCtz.o(.text+0x128): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/cc04tCtz.o(.text+0x13d): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/cc04tCtz.o(.text+0x14c): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/cc04tCtz.o(.text+0x15c): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/cc04tCtz.o(.text+0x171): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/cc04tCtz.o(.text+0x179): In function `main':
: undefined reference to `glutMainLoop'
/tmp/cc04tCtz.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[root@kkp opengl]# gcc g.cc -lGL -glut
cc1plus: warning: `lut': unknown or unsupported -g option
/tmp/ccmrIIEr.o(.text+0x11b): In function `main':
: undefined reference to `glutInit'
/tmp/ccmrIIEr.o(.text+0x128): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/ccmrIIEr.o(.text+0x13d): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/ccmrIIEr.o(.text+0x14c): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/ccmrIIEr.o(.text+0x15c): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/ccmrIIEr.o(.text+0x171): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/ccmrIIEr.o(.text+0x179): In function `main':
: undefined reference to `glutMainLoop'
/tmp/ccmrIIEr.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
ANY sample program i try i get similar errors. I don't know what i'm doing wrong. Somebody please help me.
thanks a lot for the prompt reply deiussum, i did miss 'g' while posting it . i still have the error with the -lglut and -lGL options, have given the output below. By the way have you tried programming in glut?
[root@kkp opengl]# gcc g.cc -lglut -lGL
/tmp/ccB5fXyj.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `gluErrorString'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XGetExtensionVersion'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XFreeDeviceList'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XQueryDeviceState'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `gluNewQuadric'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XListInputDevices'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `gluQuadricDrawStyle'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `cos'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `gluCylinder'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `sin'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XFreeDeviceState'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XOpenDevice'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `gluQuadricNormals'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XmuLookupStandardColormap'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `XSelectExtensionEvent'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libglut.so: undefined reference to `gluSphere'
collect2: ld returned 1 exit status
P.S : If there's ANYBODY out there who has successfully compiled glut programs(and gotten the desired output) please do reply.
Ok, now you are running into problems because you aren't linking in the GLU library, and some of the X libraries.
Also, there are some known problems with glut under RedHat. You might want to do a search on the Linux forums at http://www.opengl.org.
As a quick test, you can try adding the following libraries, though:
-lGLU -lXi -lXmu.
And yes, I've used glut. It's nice for quick little OpenGL apps, but for my final apps, I tend to use system specific calls to create the OpenGL windows.
i checked out the OpenGL GNU/Linux forum, i finally got a proper compile and the program works. Thanks a lot deiussum. i haven't got much experience in using library links in gcc, thanks to you and the guys at the OpenGL forum now i do. Thanks again.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.