Re: dlsym() fails with an executable shared library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > gcc -Wall -W -fPIC -shared -o library.so test.c -lc -Wl,-e,my_main
>
> This is a workable approach, but my_main must act as the entry point of
> the program.  The entry point is not called with argc and argv.  Take a
> look at crt1.o on your system to see what the entry point must do.

Ah, makes sense.

> > gcc -fPIC -fPIE -pie -o library.so test.c
>
> That does not make a shared library.

I'm curious, why not? It's position independent. "file" says it's a
shared object:
$ file ./library.so
./library.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not
stripped

> > This can read arguments fine, but dlsym() fails:
> >
> > ./library.so: undefined symbol: my_func
>
> You can probably fix that problem by linking with -rdynamic.

Didn't work, unfortunately, same problem.

> Perhaps we should ask: why do you want an executable shared library?

1) So that like libc, users of my library can determine the library
version by just running it.
2) For a particular convoluted use case, where an app using the
library could fork() and then exec() the library.
3) Because it can be done :)

Thanks
-Mayank



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux