Using libc.so instead of libc.so.6, or static linking

From: Mark Riordan (riordan_at_rocketmail.com)
Date: 10/31/03


Date: 30 Oct 2003 16:12:31 -0800

I am writing a shared library that uses only the most basic C library
routines.
I see that ld is placing a dependency on libc.so.6 and libstdc++.so.5
in my shared library.
(This is under Red Hat 9.0; other names would apply to other
versions.)
This means that people using my library can't run it under Red Hat < 9
unless they install a newer GCC, which they won't want to do.

In my case, the error on the older version of Linux is:
error while loading shared libraries: libstdc++.so.5: cannot
 load shared object file: No such file or directory

Is there a way I can get the linker to include only the generic
libc.so and libstdc++.so in the header?

I suppose I could bite the bullet and link staticly:

ld --strip-all -static -shared -soname libjunk.so.1 -o libjunk.so.1.1

But even there I have
a problem: on Red Hat 7.1, trying to run with the staticly-linked
shared library generated on Red Hat 9.0 gives me:

error while loading shared libraries: /usr/lib/libjunk.so.1: undefined
symbol: __gxx_personality_v0

With some digging, I found that for some reason, the shared library
was
still trying to link dynamically to libstdc++.so, and
the only generic libstdc++.so that I could find on Red Hat 7.1 was
buried in
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so.
Since libstdc++.so was in one of the standard places, and LIBPATH was
not pointing to /usr/lib/gcc-lib/i386-redhat-linux/2.96,
the system could not find libstdc++.so.
(It did work when I set LIBPATH.)
Is this a configuration problem specific to this system, or
will I have to ask all my users to modify their LIBPATHs?

As you can see, I'm confused.
Can anyone help?

Thanks much,

Mark Riordan
riordanNOTTHIS@rocketmail.com



Relevant Pages

  • Shared libraries in Red Hat
    ... I am installing SUN DS 5.2 on a RED HAT ES 3 ... My environment is not set up correctly for shared libraries: ... open shared object file: ...
    (RedHat)
  • Re: comments on OCaml?
    ... > the Microsoft went through with shared libraries. ... it seems like statically binaries are not ... Red Hat and the next? ... The design of GTK also apparently makes it impossible to access all the ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Loading Dynamic Librarys as root
    ... Is your program a root set-uid one? ... check that LIBPATH is correctly defined ... > we run this as a non-root user, the dependent shared libraries are ... > It may be easier to explain this by using the ldd command. ...
    (comp.unix.aix)