This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Question on dlopen


> Date: Thu, 13 May 1999 22:04:29 +0800
> From: Tung-Han Hsieh <thhsieh@linux.org.tw>

> Hello,
> 
> I have a question on dlopen(). Suppose that I have a "libA.so"
> which is build from
> 
> gcc -fPIC -c A.c
> gcc -shared -Wl,-soname,A -o libA.so A.o -lB -ldl -L<path of libB.a>
> 
> and I also have a "libB.a" which needs the db_open() and other
> functions

You mean db_open(), which is provided by libdb, or dlopen(), which is
provided by libdl?

In the first case, you need to link libA.so with libdb.

Also, you should specify the -L option before the -l option which
needs it.

> provided by standard libdl of glibc-2.1.1. But libA.so don't need to
> call db_open() directly, it will only call the functions of libB.a 
> directly. libB.a is compiled like this
> 
> gcc -c B.c

You should use -fpic (or -fPIC) on this command, because B.o will end
up in libA.so.

> ar cr libB.a B.o
> ranlib libB.a

The effect of all the above should be just like writing

gcc -fPIC -c A.c
gcc -c B.c
gcc -shared -Wl,-soname,A -o libA.so A.o B.o -ldl


> Now I have a main program which use dlopen() to load libA.so:
> 
> 	void *ldso;
>         if (! (ldso = dlopen("libA.so", RTLD_LAZY))) {
>             fprintf(stderr, "dlerror: %s\n", dlerror());
>             return  NULL;
>         }
> 
> But when I run the main program, the dlopen false. The error message is
> like that "the dlopen() symbol not found".
> 
> Could anyone suggest what should I do? Thank you very much.

How are you linking the main program?  You should be linking it like:

gcc -c main.c
gcc main.o -o main -ldl

-- 
Geoff Keating <Geoff.Keating@anu.edu.au>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]