nVidia drivers, glx, linking, headache :(


I have a problem with building OGL apps under linux (specifically Mandrake8.0). I’ve installed the nvidia drivers and GLX rpms and that seems to have gone ok. When I query rpm to see what files are installed where, then everything (at least to my newbie eyes) looks ok.

now, when I get around to building an app, I can’t get it to link

I’m trying this for the build step:

gcc -L/usr/X11R6/lib -L/usr/X11R6/lib/modules/extensions -lGL -lglx main.cpp

but I get a whole load of link errors. I don’t suppose someone could tell me what I need to link against to just get a simple app building?? (I don’t need GLU or Glut, so perhaps that simplifies things a little

thanks for any help


What are the missing symbols? OpenGL related I assume.

Try moving the main.cpp to just after the gcc, ie.

gcc main.cpp -L/usr/X11R6/lib -L/usr/X11R6/lib/modules/extensions -lGL -lglx

ok, tried that, didn’t work (I didn’t think it would tho’!! surely the order of commands to gcc doesn’t matter?)

anyway, thanks for trying

I’ve tried linking to pretty much every library I can see, X11, m, xf86vm, Xi, Xmu, and some other ones, but I still get symbols referenced that are undefined, I’ll list a couple here, but there are far more


as I say, there are far, far more…but, judging by their names, they seem to be “related” to the ones listed here…by that, I mean that I would expect them to live in the same lib, so solving one of the above should solve a few of the others…

thanks for any help…


I should mention that all of those link errors are reported from within the glx lib. I’m not using those functions myself, glx is.


In an ideal world the order of arguments on the gcc command-line wouldn’t matter, but they do seem to under certain circumstances (eg. library order does matter I think).

Looking at a Makefile for an old OpenGL application I’ve developed under Linux, it seems to want

-lXi -lXmu -lm

in addition to those you’ve listed. Furthermore it doesn’t seem to need to be explicitly linked to libglx.

Did you try without -lglx, or with -lglx before -lGL?

Have you tried ‘g++’ rather than ‘cpp’ (if your code genuinely is C++)?

That’s me done for ideas I’m afraid…

thanks, I’ll try that once I’m back in front of my Linux box…

I seem to remember that I thought I had to link with glx because the first time I tried to build I had glX functions listed in the linker errors as undefined, e.g. glXMakeContextCurrent.

I didn’t realise that link order was important in Linux (well, the gnu linker)…definately something to remember for the future.

thanks for this, I’ll let you know how it goes (or not! )

an update on my predicament, for anyone who’s still interested

I have a small program that I cribbed from somewhere, unfortunately I can’t remember where right now …but the important thing is that if I build it on my Radeon equipped PC, with a clean Mandrake8.0 install, it builds fine (I chose the “experimental hardware acceleration option” when I installed). If I try to build it on my nVidia PC, then I get linker errors regarding the GLX functions.

any ideas?

for reference, here’s the small app I’m trying to compile…the semantics are unimportant really, the link error is the main thing…

#include <GL/glx.h>
#include <GL/gl.h>
#include <stdio.h>
#include <stdlib.h>

static Bool WaitForNotify(Display *d, XEvent *e, char *arg)
return (e->type == MapNotify) && (e->xmap.window == (Window) arg);

static int sAttribList[] = {
None };

int main(void)
Display *dpy;
XVisualInfo *vi;
XSetWindowAttributes swa;
Window win;
GLXContext cx;
XEvent event;
int swap_flag = GL_FALSE;

dpy = XOpenDisplay(0);

if ((vi = glXChooseVisual(dpy, DefaultScreen(dpy), sAttribList)) == NULL) {
    fprintf(stderr, "ERROR: Can't find suitable visual!

return 0;

cx = glXCreateContext(dpy, vi, 0, GL_TRUE);

swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi-&gt;screen),
    vi-&gt;visual, AllocNone);
swa.border_pixel = 0;
swa.event_mask = StructureNotifyMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi-&gt;screen), 0, 0, 100, 100, 0,
    vi-&gt;depth, InputOutput,
    CWBorderPixel | CWColormap | CWEventMask,

XMapWindow(dpy, win);

XIfEvent(dpy, &event, WaitForNotify, (char *)win);

glXMakeCurrent(dpy, win, cx);

/* ... */


thanks for any help


I should also mention that I use

gcc -L/usr/X11R6/lib -lGL -lX11 glx_init.c

to build it


final update

I tried using nm to dump the symbols from libGL, and the functions I want definately are there. how odd. anyway, if I use dlopen/dlsym to dynamically link to the lib, then I can quite happily retrieve the symbol.

I guess dynamically linking is a bit more robust anyway.

thanks for your help.

You really shouldn’t have to use dlopen/dlsym to do this!

I think your install of the nvidia drivers must be broken somehow.

I tried your sample code and compile line and it worked for me with no unresolved symbols.

Here’s the list of libraries the executable ends up requiring:

amethyst> ldd a.out
libGL.so.1 => /usr/lib/libGL.so.1 (0x40025000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40062000)
libc.so.6 => /lib/i686/libc.so.6 (0x40142000)
libGLcore.so.1 => /usr/lib/libGLcore.so.1 (0x40272000)
libm.so.6 => /lib/i686/libm.so.6 (0x40616000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4063a000)
libdl.so.2 => /lib/libdl.so.2 (0x40648000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

hmmm…this is stranger than I thought then

from a code pov, I’m happy to dynamically link, that’s not a problem (in fact, I’m happier doing it this way ). but I’d like to find out why this problem is occurring. does anyone from nVidia lurk in this part of the web board, or do they just hang out in the advanced section? can they throw any light on this problem?

I’ve tried downloading and forcing the reinstall of the kernel and glx rpms, but I still get the same link errors (and now that I have both computers next to each other, I can tell you what they are!)

undefined reference to glXChooseVisual' undefined reference toglXCreateContext’
undefined reference to `glXMakeCurrent’

it’s all very odd. as I said before, the symbols are definately in the libGL.so. but for some reason the linker won’t let me get at them! how frustrating

apart from this problem, everything to do with OGL seems fine in Linux, the gears demo and the morph demo go at a million miles an hour

oh, I also tried installing from the tar’s, but still the same problem.

have the files on nvidia’s site changed recently? has someone “fixed” something that’s broken something else?

thanks for any help, and thanks to Richard for his help so far.


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.