[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dlsym() and C++

Magnus Norddahl wrote:

> > Why are you attempting to use dlopen() to access libMesaGLU.so? These
> > libraries are generally intended to be used with an -l flag on the
> > linker's command line. Part of ld's function is to resolve all the
> I want to have a libclan.so that includes all the implementations at once.
> Including the svgalib, x11, mesa, glide, ggi, ptc and sdl (not all have been
> written yet, you get the idea). But very importantly, I do NOT want users of

I understand that.

> > Maybe if you did a dlopen on libMesaGL.so with the flags RTLD_NOW and
> > RTLD_GLOBAL before opening libMesaGLU.so, it would resolve properly.
> > RTLD_NOW resolves all external symbols immediately. RTLD_GLOBAL makes
> > those symbols visible to other shared libs that may be loaded.

And the RTLD_GLOBAL flag will fix your problem of making symbols from a
library available to others.

Actually, when you make a library that uses other libraries, you should
specify it when building the library, with -lfoo options, just like
building an executable. There is no error if you don't put them, but if
you do put them, you won't have to preload the other library with
RTLD_GLOBAL so that it work, just loading it will make ld.so check if
the requisite library is already loaded. Of course, for Mesa, you don't
have any control over how it is build, so you'll have to use RTLD_GLOBAL
to load it. But if you do it, others will thank you. :-)

Pierre Phaneuf
Ludus Design, http://ludusdesign.com/