PDA

View Full Version : Running OpenGL on CentOS 5.4



Hassoon
03-22-2010, 07:09 PM
Hello everyone,

My goal is pretty simple: get OpenGL up and running on my Linux box.

Since I'm running CentOS (Red Hat without the logos), I decided to play it safe and use YUM to install the proper libraries for my configuration:

yum install freeglut freeglut-devel libX11-devel mesa-libGLU-devel

I've also installed the proper Nvidia drivers.

Everything installed fine.

To try things out, I went ahead and used an example from here:

http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html

I chose dinoshade.c

When compiling using the following command:

gcc dinoshade.c -lglut

I get the following errors:

---Begin errors---

/tmp/ccItGNse.o: In function `main':
dinoshade.c:(.text+0x1d1b): undefined reference to `glPolygonOffsetEXT'
collect2: ld returned 1 exit status

---End errors---

I assumed it was a library linking problem, so I searched for gl.h and I got the following:

/usr/share/doc/NVIDIA_GLX-1.0/include/GL/gl.h
/usr/include/GL/gl.h

The gl.h from the first line is because of the Nvidia drivers I installed for the machine.

I've searched all over for a solution, but I'm not quite sure what the best way to go is at this point.

A-N-Y help would be greatly appreciated.

Thank you so much in advance.

sqrt[-1]
03-22-2010, 11:57 PM
That is an ancient example, it will probably work if you comment out the GL_EXT_polygon_offset defined sections.

The other way of fixing it is to ensure the extension entry points get included and loaded. Try
http://www.opengl.org/sdk/libs/GLee/
or
http://www.opengl.org/sdk/libs/GLEW/

I am not a linux guru, so someone else can probably help you more.

Hassoon
03-23-2010, 01:05 AM
]That is an ancient example, it will probably work if you comment out the GL_EXT_polygon_offset defined sections.

The other way of fixing it is to ensure the extension entry points get included and loaded. Try
http://www.opengl.org/sdk/libs/GLee/
or
http://www.opengl.org/sdk/libs/GLEW/

I am not a linux guru, so someone else can probably help you more.


Thanks for your reply...

You are absolutely right...it's a pretty old example, and I'd rather have the most basic stuff compile first before I delve into writing a ray tracer or something ;)

For what it's worth, here's some more interesting errors I'm getting from another piece of code that further allude to the possibility of this being a library linking issue:

---Begin errors---

/usr/bin/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
/usr/bin/ld: skipping incompatible /usr/lib/libXmu.so when searching for -lXmu
/usr/bin/ld: skipping incompatible /usr/lib/libXi.so when searching for -lXi
/usr/bin/ld: skipping incompatible /usr/lib/libXext.so when searching for -lXext
/usr/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /usr/lib/libGLU.so when searching for -lGLU
/usr/bin/ld: skipping incompatible /usr/lib/libglut.so when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libglut.a when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
/usr/bin/ld: skipping incompatible /usr/lib/libXmu.so when searching for -lXmu
/usr/bin/ld: skipping incompatible /usr/lib/libXi.so when searching for -lXi
/usr/bin/ld: skipping incompatible /usr/lib/libXext.so when searching for -lXext
/usr/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /usr/lib/libGLU.so when searching for -lGLU
/usr/bin/ld: skipping incompatible /usr/lib/libglut.so when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libglut.a when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
/usr/bin/ld: skipping incompatible /usr/lib/libXmu.so when searching for -lXmu
/usr/bin/ld: skipping incompatible /usr/lib/libXi.so when searching for -lXi
/usr/bin/ld: skipping incompatible /usr/lib/libXext.so when searching for -lXext
/usr/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /usr/lib/libGLU.so when searching for -lGLU
/usr/bin/ld: skipping incompatible /usr/lib/libglut.so when searching for -lglut
/usr/bin/ld: skipping incompatible /usr/lib/libglut.a when searching for -lglut
/usr/bin/ld: cannot find -lgl
collect2: ld returned 1 exit status

---End errors---

Googling the problem leads to suggestions of having to edit the $LD_LIBRARY_PATH, which is in better circumstances a very bad idea.

Again, before messing with library links and accidentally spawning broken ones, I thought I would have your educated opinion first :)

This is all running on CentOS 5.4 x64, for what it's worth.

Please let me know if there's any information I have to provide.

ZbuffeR
03-23-2010, 01:38 AM
The "skipping incompatible" messages means that when building a 64 bits executable, it skips 32 bits libraries, which is a good thing. These are not errors, only harmless messages.

"/usr/bin/ld: cannot find -lgl" however means that no libgl library was found. Try with -lGL *only*, the case is important.

If the linker still can't find 64 bits libs, it means there are missing :)

Check is 64 bits libs are installed or available in your repositories :


yum info *libGL.x86_64*

Hassoon
03-23-2010, 02:19 AM
The "skipping incompatible" messages means that when building a 64 bits executable, it skips 32 bits libraries, which is a good thing. These are not errors, only harmless messages.

"/usr/bin/ld: cannot find -lgl" however means that no libgl library was found. Try with -lGL *only*, the case is important.

If the linker still can't find 64 bits libs, it means there are missing :)

Check is 64 bits libs are installed or available in your repositories :


yum info *libGL.x86_64*



Thanks for taking the time :)

Well, here's what referring to -lGL does:

command:

gcc dinoshade.c -lGL

---Begin errors---
/tmp/ccQlhbql.o: In function `makeFloorTexture':
dinoshade.c:(.text+0xf3): undefined reference to `gluBuild2DMipmaps'
/tmp/ccQlhbql.o: In function `extrudeSolidFromPolygon':
dinoshade.c:(.text+0x70c): undefined reference to `gluNewTess'
dinoshade.c:(.text+0x729): undefined reference to `gluTessCallback'
dinoshade.c:(.text+0x73f): undefined reference to `gluTessCallback'
dinoshade.c:(.text+0x755): undefined reference to `gluTessCallback'
dinoshade.c:(.text+0x778): undefined reference to `gluBeginPolygon'
dinoshade.c:(.text+0x7df): undefined reference to `gluTessVertex'
dinoshade.c:(.text+0x7f7): undefined reference to `gluEndPolygon'
/tmp/ccQlhbql.o: In function `redraw':
dinoshade.c:(.text+0xdcb): undefined reference to `glutGet'
dinoshade.c:(.text+0x14d3): undefined reference to `glutSolidSphere'
dinoshade.c:(.text+0x1500): undefined reference to `glutGet'
dinoshade.c:(.text+0x1539): undefined reference to `glutSwapBuffers'
/tmp/ccQlhbql.o: In function `motion':
dinoshade.c:(.text+0x1632): undefined reference to `glutPostRedisplay'
dinoshade.c:(.text+0x16d3): undefined reference to `glutPostRedisplay'
/tmp/ccQlhbql.o: In function `idle':
dinoshade.c:(.text+0x16e3): undefined reference to `glutGet'
dinoshade.c:(.text+0x177f): undefined reference to `glutPostRedisplay'
/tmp/ccQlhbql.o: In function `controlLights':
dinoshade.c:(.text+0x17ca): undefined reference to `glutIdleFunc'
dinoshade.c:(.text+0x17d9): undefined reference to `glutIdleFunc'
dinoshade.c:(.text+0x1902): undefined reference to `glutPostRedisplay'
/tmp/ccQlhbql.o: In function `visible':
dinoshade.c:(.text+0x1929): undefined reference to `glutIdleFunc'
dinoshade.c:(.text+0x193f): undefined reference to `glutIdleFunc'
/tmp/ccQlhbql.o: In function `key':
dinoshade.c:(.text+0x1968): undefined reference to `glutPostRedisplay'
/tmp/ccQlhbql.o: In function `special':
dinoshade.c:(.text+0x1980): undefined reference to `glutPostRedisplay'
/tmp/ccQlhbql.o: In function `main':
dinoshade.c:(.text+0x1a06): undefined reference to `glutInit'
dinoshade.c:(.text+0x1b23): undefined reference to `glutInitDisplayMode'
dinoshade.c:(.text+0x1b2d): undefined reference to `glutInitDisplayString'

...MANY MORE "undefined reference" errors...

dinoshade.c:(.text+0x1e1f): undefined reference to `gluLookAt'
dinoshade.c:(.text+0x1eb0): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

---End errors---

And here's what yum info *libGL.x86_64* reports:

Installed Packages
Name : mesa-libGL
Arch : x86_64
Version : 6.5.1
Release : 7.7.el5
Size : 23 M
Repo : installed
Summary : Mesa libGL runtime libraries and DRI drivers
URL : http://www.mesa3d.org
License : MIT/X11
Description: Mesa libGL runtime libraries and DRI drivers.

I feel like I'm so close to a solution...it's like one library link away...just not sure how :(

Again, I'm EXTREMELY grateful for your time. I hope I could return the favor.

Hope you still have the patience to help me slay this beast ;)

Stephen A
03-23-2010, 02:26 AM
Since you are using GLU and GLUT, you need to link these libraries, too:

gcc dinoshade.c -lGL -lglu -lglut

Play with the case (i.e. glu vs GLU) if that doesn't work.

Hassoon
03-23-2010, 02:53 AM
Since you are using GLU and GLUT, you need to link these libraries, too:

gcc dinoshade.c -lGL -lglu -lglut

Play with the case (i.e. glu vs GLU) if that doesn't work.

Same as the error in my first post :(

---Begin errors---

/tmp/cciv7Qov.o: In function `main':
dinoshade.c:(.text+0x1d1b): undefined reference to `glPolygonOffsetEXT'
collect2: ld returned 1 exit status

---End errors---

Played with all different cases...still no go...

ZbuffeR
03-23-2010, 03:30 AM
Same error, same solution :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=274516#Post2745 16

New entry point added by GL extensions or after GL 1.2 have to be asked at runtime, they can not be linked during compile/link stages. The OpenGL ABI (application binary interface) is 1.2 under linux.

You can choose, roughly sorted with easiest solutions first :
1) remove reference to "extended" entry points, super easy but will change the behavior of the program
2) or use GLEW/Glee, easy
3) or do the right thing to grab a function pointer at runtime with glXGetProcAddress (http://www.opengl.org/sdk/docs/man/xhtml/glXGetProcAddress.xml), which is more involved

Dark Photon
03-23-2010, 06:00 PM
4) Another solution. Since this is just a quick GL test and and you just want it to work, look at what your libGL is advertising for PolygonOffset, and just change the code to use that:

nm -Do /usr/lib64/libGL.so | grep glPolygonOffset

Also, typically you want to specify libraries in order of highest to lowest, like this:

gcc -o dinoshade dinoshade.c -lglut -lGLU -lGL