Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dlopen() and symbols and none shared libraries

215 views
Skip to first unread message

Aurel Balmosan

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Hi all,

I have a major problem with dynamic loaded shared objects. dlopen() fails
because it can not resolve symboles defined in normal ".a" libraries linked with
the program.

Here an example:

C-Source: x.c
Compiled with: gcc -o x x.c -ldl
-------------------------
#include <dlfcn.h>

void MyMainFunction()
{ printf("My main function\n");
}

void main()
{ void *hdl=dlopen("./y.so", RTLD_NOW);
void (*fnc)();
if (!hdl) { printf("dlopen(%s)\n", dlerror()); exit(1); }
printf("My first main\n");
fnc=dlsym(hdl, "MySharedFunction");
if (!fnc) { printf("dlsym(%s)\n", dlerror()); exit(1); }
fnc();
printf("My second main\n");
exit(0);
}
--------------------------

C-Source:y.c
Compiled with: gcc -fPIC -shared -o y.so y.c
---------------------------------
#include <stdio.h>
void MySharedFunction()
{ printf("My first shared\n");
MyMainFunction();
printf("My second shared\n");
}
----------------------------------

Running x give following output:
x: can't resolve symbol 'MyMainFunction'
dlopen(Unable to resolve symbol)

The same happens if the symbol is from a static linked library ("libxyz.a") It
happens also when the x.o is generated as shared as follows:

gcc -fPIC -shared -c x.c; gcc -o x x.o -ldl

In case the function MyMainFunction is in another shared object xx.so only
containing that function. And the dlopen() flags are RTLD_NOW|RTLD_GLOBAL every
thing is ok.

The same code runs on Solaris-2.5.1, Solaris-2.6, DEC-Unix-3.2, DEC-Unix-4.0 and
other UNIX. It looks like that the local symbols are not known to the dynamic
loader. Why? I think that this is a bug. Who can help me?

Bye,
Aurel.


--
=========================================================
Aurel Balmosan | a...@orga.com, au...@orga.com
=========================================================


Richard Jones

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Aurel Balmosan <a...@orga.com> wrote:
> Hi all,

> I have a major problem with dynamic loaded shared objects. dlopen() fails
> because it can not resolve symboles defined in normal ".a" libraries linked with
> the program.

Does compiling the main program with -rdynamic make it
work?

Rich.

--
Richard Jones rjo...@orchestream.com Tel: +44 171 460 6141 Fax: .. 4461
Orchestream Ltd. 262a Fulham Rd. London SW10 9EL. "you'll write in
PGP: www.four11.com telegraphic, or you won't write at all" [Céline]
Copyright © 1998 Richard W.M. Jones

Aurel Balmosan

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Aurel Balmosan wrote:

> I have a major problem with dynamic loaded shared objects. dlopen() fails
> because it can not resolve symboles defined in normal ".a" libraries linked with
> the program.

Thank you all for responding via e-mail.Now i use -Wl,-export-dynamic when linking
and it works fine.

Bye,
Aurel.

--
================================================================
Aurel Balmosan | au...@xylo.owl.de, a...@orga.com
http://gaia.owl.de/~aurel/ |
================================================================


Paul Flinders

unread,
Mar 4, 1998, 3:00:00 AM3/4/98
to

Richard Jones <rjo...@orchestream.com> writes:

> Aurel Balmosan <a...@orga.com> wrote:
> > Hi all,
>

> > I have a major problem with dynamic loaded shared objects. dlopen() fails
> > because it can not resolve symboles defined in normal ".a" libraries linked with
> > the program.
>

> Does compiling the main program with -rdynamic make it
> work?

Not with a recent ld - the dlopen man page is out of sync.

You want --export-dynamic as a linker flag. Aurel's code works OK then

--
Paul

0 new messages