dlopen + dlsym problem (Full Version)

All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum



Message


kingbing -> dlopen + dlsym problem (Mar. 8, '06, 6:38:18 AM)

Hi folks. I'm trying to build something using libglade, which sits on top of gtk. It's got a nice feature where it will automatically wire up events to event handlers (you specify an xml file that describes the interface, and the functions it calls when things happen).

This all works via dlopen/dlsym (via gmodule in glib), but this doesn't seem to work in Interix.

If you call dlopen(NULL,0) you should get a handle back to all the symbols in the current image. Calling dlsym from that should get you the address of a function in your own program. Unfortunately, it doesn't work - dlsym can only find items in shared libraries loaded by the current image.

Here's an example program:

#include <dlfcn.h>

int glib_underscore_test(void) { return 42; }
int main()
{
int i=glib_underscore_test();
void *f1=(void *)0, *f2=(void *)0, *handle;
handle=dlopen((void*)0,0);
if(handle)
{
f1=dlsym(handle,"dlsym");
if(!f1)
printf("%s\n",dlerror());
f1=dlsym(handle,"glib_underscore_test");
if(!f1)
printf("%s\n",dlerror());
f2=dlsym(handle,"_glib_underscore_test");
if(!f2)
printf("%s\n",dlerror());
}
else
printf(dlerror());
}

On my box, the call to find "dlsym" does not cause an error, but the calls to find "glib_underscore_test" and "_glib_underscore_test" do.

Anyone got any ideas?

Cheers
Matt




kingbing -> RE: dlopen + dlsym problem (Mar. 10, '06, 11:24:22 AM)

Sorted. From the man page to ld:

-E, --export-dynamic
When creating an ELF file, add all symbols to the dynamic-symbol
table. Normally, the dynamic-symbol table contains only symbols that
are used by a dynamic object. This option is needed for some uses of
dlopen(3).

Just add --export-dynamic to the Makefile and everything's lovely.

Cheers!
Matt




Page: [1]



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.031