plash
[Top][All Lists]
Advanced

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

Re: [Plash] undefined reference to address@hidden'


From: Mark Seaborn
Subject: Re: [Plash] undefined reference to address@hidden'
Date: Sun, 15 Oct 2006 13:34:53 +0100 (BST)

Thomas Leonard <address@hidden> wrote:

> Hi again,
> 
> I've managed to compile simple C programs using plash, but I'm getting
> odd errors with GTK programs:
> 
> $ pola-run --prog /usr/bin/make -fw /
> cc `pkg-config --cflags gtk+-2.0`  `pkg-config --libs gtk+-2.0`
> hello.c   -o hello
> /usr/lib/plash/lib/libpthread.so.0: undefined reference to
> address@hidden'
> /usr/lib/plash/lib/libpthread.so.0: undefined reference to
> address@hidden'
> /usr/lib/plash/lib/libpthread.so.0: undefined reference to
> address@hidden'
> /usr/lib/plash/lib/libpthread.so.0: undefined reference to
> address@hidden'
> /usr/lib/plash/lib/libpthread.so.0: undefined reference to
> address@hidden'
> collect2: ld returned 1 exit status
> make: *** [hello] Error 1
> 
> hello.c and Makefile are both trivial, but I've attached them anyway.
> 
> Any idea what causes this?

It turns out this is happening because the linker is trying to link
/lib/libc.so.6 against /usr/lib/plash/lib/libpthread.so.0, which fails
because you cannot mix shared objects that are part of Plash's libc
with those from the normal libc.

The reason that happens is that ld has different rules for finding:
 * libraries that are explicitly listed on ld's command line with
   the "-l" option;
 * libraries that a shared object declares itself as depending on
   via a DT_NEEDED declaration.

For the latter, ld searches LD_LIBRARY_PATH.  For the former, it
doesn't.  (This behaviour is described in ld's man page in the section
on "-rpath-link".)

A smaller test case is just to link against librt:

  echo "int main() { return 0; }" >test.c
  pola-run -B -fw . -e /usr/bin/gcc test.c -o test -lrt

librt.so has a dependency on libpthread.so:
  $ objdump -x /lib/librt.so.1 | grep NEEDED
  NEEDED      libc.so.6
  NEEDED      libpthread.so.0
  NEEDED      ld-linux.so.2

This means that ld will search LD_LIBRARY_PATH for libpthread.so.0,
and find Plash's version (/usr/lib/plash/lib/pthread.so.0).

One way around this is to tell ld explicitly to link libpthread (which
"pkg-config --libs gtk+-2.0" does not do):

  pola-run -B -fw . -e /usr/bin/gcc test.c -o test -lrt -lpthread

Or you can use the "-rpath-link" option to specify a directory to be
searched before LD_LIBRARY_PATH:

  pola-run -B -fw . -e /usr/bin/gcc test.c -o test -lrt -Wl,-rpath-link=/lib

(This must be "/lib" not "/usr/lib" because ld will search for
"libthread.so.0" not "libpthread.so".)

But neither of these workarounds are going to be practical for using
with arbitrary packages' build scripts, are they?  I guess we'll have
to stop using LD_LIBRARY_PATH to get the dynaminc linker to use
Plash's libc and instead overlay /usr/lib/plash/lib on top of /lib.

Cheers,
Mark




reply via email to

[Prev in Thread] Current Thread [Next in Thread]