On Thu, Aug 08, 2002 at 03:14:21PM +0200, Erland Lewin wrote:
> Hello,
>
> I have problems with pthread-programs dumping core on thread
> initialization depending on how linking is done.
> I would appreciate help on what the correct way for linking libraries is.
> See the files at the end of this E-mail. If they are compiled as follows:
>
> cc -g -c -o testlib.o testlib.c
> ld -shared testlib.o -lpthread -o libtestlib.so
> cc -g -c -o testapp.o testapp.c
> cc -L. testapp.o -ltestlib -lpthread -o testapp
>
> and testapp is run, it will crash/hang in pthread_create. Why?
> However, if only one of testlib and testapp are linked with -lpthread,
> then the resulting program will execute correctly.
> From what I have previously understood, shared libraries must be
> linked with the shared libraries that they use in order for libc
> versioning to work properly (that is, it would be incorrect for testlib
> not to be linked with -lpthread, because then the knowledge about which
> version of -lpthread was used is lost. Is this wrong?
> I'm using gcc 3.0.2, binutils 2.12.1, gnu libc 2.2.2.
> I'd be most grateful if someone could clarify the situation, and
> explain the correct way of doing things. And maybe even point me to the
> relevant docs. Please cc: any replies to the list to me.
You're right; shared libraries must be linked with the shared libraries
that they use. All shared libraries that they use, which includes libc
and often libgcc_s. The rule is, don't ever use "ld" to link a shared
library. You should only be doing that for custom static binaries, if
ever. Use "cc -shared testlib.o -lpthread -o libtestlib.so" (and maybe
-Wl,-soname,libtestlib.so") and see if that helps.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer