More on using dynamic libraries

I have an array of void pointers to serve as handles to dynamic libraries.
In the trivial case, the library will be the same for each case. I would
expect the array of pointers to be all the same also. However, this is not
the case. Why?
i.e.

for (i=0; i<M; i++) {
hdll = dlopen(“libfoo.so”, RTLD_NOW );
}

Should hdll for all i<M be equal?

Chris Rose <esorcc@hotmail.com> wrote:

I have an array of void pointers to serve as handles to dynamic libraries.
In the trivial case, the library will be the same for each case. I would
expect the array of pointers to be all the same also. However, this is not
the case. Why?
i.e.

for (i=0; i<M; i++) {
hdll > = dlopen(“libfoo.so”, RTLD_NOW );
}

Should hdll > for all i<M be equal?

_No. You will get a different handle, even though the lib isn’t actually
mapped multiple times.
\

cburgess@qnx.com_

Colin Burgess <cburgess@qnx.com> wrote:

Chris Rose <> esorcc@hotmail.com> > wrote:

for (i=0; i<M; i++) {
hdll > = dlopen(“libfoo.so”, RTLD_NOW );
}

Should hdll > for all i<M be equal?

No. You will get a different handle, even though the lib isn’t actually
mapped multiple times.

_But I don’t think it would be wise to rely on that, would it?

POSIX says:

A successful dlopen() shall return a handle which the caller may use
on subsequent calls to dlsym() and dlclose(). The value of this
handle should not be interpreted in any way by the caller.
\

Wojtek Lerch QNX Software Systems Ltd._

Wojtek Lerch <wojtek_l@yahoo.ca> wrote:
: POSIX says:

: A successful dlopen() shall return a handle which the caller may use
: on subsequent calls to dlsym() and dlclose(). The value of this
: handle should not be interpreted in any way by the caller.

I’ll mention this in the docs.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems