Hi all,

I'm having a problem with a dynamically loaded library (dlopen via gmodule part of glib) that I was hoping someone could shed some light on. The situation is as follows:

I have a c++ program developed for Linux (RHEL5) using gcc 4.1.2 with the following library dependency tree:

EXE --> (statically linked) someliba --> (dynamically linked) mycommonlib
+----> (dynamically loaded) somelibb --> (dynamically linked) mycommonlib

In case that's not clear, the executable statically links someliba and someliba dynamically links mycommonlib (i.e., -lmycommonlib). The executable dyamically loads (i.e., dlopen) somelibb and somelibb dynamically links mycommonlib.

What I'm seeing is that mycommonlib is actually loaded in memory twice. This causes a problem because a singleton in mycommonlib ends up having two instances.

If, however, I change the executable to dynamically link someliba, the problem goes away (i.e., mycommonlib only loaded once). That would be a good solution except that dynamically linking someliba causes problems at shutdown (I think this is caused by destructors in static variables in a library we're using; Loki...haven't had a chance to debug yet).

I am specifying ~G_MODULE_BIND_MASK as the link flags to g_module_open which should be equivalent to RTLD_NOW | RTLD_GLOBAL to dlopen.

My question is whether there's a way to prevent mycommonlib from being loaded twice while still having someliba linked statically. I'm actually somewhat confused why it's ever loaded twice, actually.

Thanks for any help,
-John