This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
|
I am using gcc-2.95.2 and glibc-2.2 (sadly, I am
using RH7.0's glibc-2.2) w/ Linux 2.4.2. Now perhaps I don't know how
dlopen() is supposed to work, but....
If I try to dlopen() a shared library with
RTLD_LAZY, and the library in question references an external symbol that is not
defined in a system library (like libc or something), dlopen() fails and dlerror
will print: "X.so: undefined symbol: FOO".
For example:
lib1.c:
#include <stdio.h>
extern int x(void);
void lib1_func(void) { printf("x = %d\n", x);
}
-------------------
test.c:
#include <stdio.h>
int x(void) { return 99; }
int main(void) {
void *h;
h = dlopen("./lib1.so",
RTLD_LAZY);
if (!h) { printf("%s\n",
dlerror()); }
if (h) dlclose(h);
return 0;
}
--------------------
$ cc -c lib1.c
$ cc -c test.c
$ ld -shared lib1.o -o lib1.so
$ cc test.o -o test -ldl
$ ./test
./lib1.so: undefined symbol: x
I thought that RTLD_LAZY forced symbols to be evaluated as
they are loaded from the shared object; thus dlopen() would not try to load
all of ./lib1.so's symbols immediately upon opening; that would be deferred
until, say, I tried to load lib1_func with dlsym(), at which point it would try
to resolve x() (and, I would hope, it would be resolved to the 'x' found in
test.o but... ?)
Also I am wondering why I don't get a message like
"./lib1.so: undefined symbol: printf"
|
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |