This is the mail archive of the gcc@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]
Other format: [Raw text]

How to make an application look somewhere other than /lib for ld-linux.so.2


Hello all

I apologize if this is off topic for this list - I wasn't sure exactly where to ask but I thought this would be a good place to start:

I'm trying to get myself a group of libraries that I can distribute with my program so that they'll run on any distro. I run into problems all the time when different distros have different versions of system libraries like libstdc++, libgcc, libc, etc.

So, I built myself a new gcc-3.4.4 compiler and build a simple "hello world" program with it on a RH8 machine. An ldd on this program yields
[mark@locutus helloworld]$ ldd a.out
libstdc++.so.6 => /cdl/apps/.software/linux/gcc-3.4.4-x86-x86/lib/libstdc++.so.6 (0x40015000)
libm.so.6 => /lib/i686/libm.so.6 (0x40102000)
libgcc_s.so.1 => /cdl/apps/.software/linux/gcc-3.4.4-x86-x86/lib/libgcc_s.so.1 (0x40124000)
libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
[mark@locutus helloworld]$


Note that ldd is using the libstdc++ library that got built when the compiler was built - this seems like a good thing to me.

To make this application run on a Red Hat 7.3 machine, I grabbed the system libraries that a.out depends upon (libc, libm) and copied them into my application's directory and changed LD_LIBRARY_PATH to point there. Now ldd outputs:
[mark@locutus helloworld]$ ldd a.out
libstdc++.so.6 => /cdl/apps/.software/linux/gcc-3.4.4-x86-x86/lib/libstdc++.so.6 (0x40015000)
libm.so.6 => ./libm.so.6 (0x400ee000)
libgcc_s.so.1 => /cdl/apps/.software/linux/gcc-3.4.4-x86-x86/lib/libgcc_s.so.1 (0x40110000)
libc.so.6 => ./libc.so.6 (0x40119000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
[mark@locutus helloworld]$


Note that ldd now picks up my local copies of libc and libm, but not of ld-linux. This program runs like this OK on Red Hat 7.3 when built on a RH8 machine, but not on an RHEL linux machine because the run-time linker is trying to use /lib/ld-linux.so.2 with my local copy of libc.so.6. The exact error message is:
[mark@hugh helloworld]$ ./a.out
./a.out: relocation error: ./libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux.so.2 with link time reference
[mark@hugh helloworld]$


This makes sense to me - the version of ld-linux.so and libc must match.

So - the question is: How do I do this? Even though LD_LIBRARY_PATH points to ./ as it's first entry, ldd still looks in /lib first for ld-linux.so.2. I've tried the rpath option to ld at link time, but that doesn't work either. It seems that thing is somehow hardcoded to look in /lib for this library.

Is there a way to somehow configure gcc build executables that look elsewhere for ld-linux.so.2, or is what I'm trying to do simply not possible? I'd really like to have a set of libraries with my program so that it's binary compatible with other distros... there must be a way. If anyone has any tips or advice I'd appreciate it.

Thanks
Mark


Mark Cuss, B. Sc. Real Time Systems Analyst System Administrator CDL Systems Ltd Suite 230 3553 - 31 Street NW Calgary, AB, Canada

Phone: 403 289 1733 ext 226
Fax: 403 289 3967
www.cdlsystems.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]