This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC 4.6.1: ld cannot find shared libraries when in sysroot
- From: Ian Lance Taylor <iant at google dot com>
- To: Zhengxiong Zhang <zzhan at umich dot edu>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 14 May 2012 15:08:04 -0700
- Subject: Re: GCC 4.6.1: ld cannot find shared libraries when in sysroot
- References: <4FAF4EC4.2080408@umich.edu>
Zhengxiong Zhang <zzhan@umich.edu> writes:
> I am trying to build some software in a 32-bit sysroot that shares the
> same directory organization as my 64-bit system. In my project, I
> build a dynamic library that links to other dynamic libraries as
> follows:
>
> g++ -o libmylibrary.so -Wl,-Bdynamic -shared --sysroot=/sysroot {bunch
> of objects} -m32 -lsomeotherlibrary
>
> I then attempt to build an application that links to my static library
> as follows:
>
> g++ -o myprog --sysroot=/sysroot {bunch of objects} -m32 -lmylibrary
>
> However, this time I get a bunch of errors like this:
>
> /usr/bin/ld: warning: libsomeotherlibrary.so needed by
> libmylibrary.so, not found (try using -rpath or -rpath-link)
> [bunch of errors about undefined references to someotherlibrary]
>
> Adding -Wl,-rpath-link=/sysroot/usr/lib causes myprog to successfully
> link. This behavior confuses me because it seems to me that ld should
> be able to find libsomeotherlibrary.so in /sysroot/usr/lib/ just like
> it did when I built libmylibrary.so. Can someone explain this to me
> and describe how I can change my build process to avoid this?
How did you build the GNU binutils? If you configure the linker with
the right --sysroot option at configure time, I think it will work.
However, this ought to work anyhow. I think the bug is that if you
don't use --sysroot when configuring the linker, the default library
path is empty. This should be set based on whether --sysroot is used at
runtime, not on whether it is used at configure time.
Ian