Why Not Shared Libraries?

From the view point of memory space and storage space economy, why not moving to the shared library environment? Don't miss the chance to use your computing resources more effectively.



Information on Shared Libraries

  1. Web Sites
  2. The best site that I know of is "MkLinux Shared Library Support" by Paul DuBois. You can also go visit a nice site by Yasutome titled "MkLinux Installation Records" .

  3. Caution (Aug. 2, 1997)
  4. The following installation prescription is now more or less obsolete, since the latest update ( Update 4 ) comes with shared library support. If you have already Update 4 fully installed, you are basically done. If you haven't, you should apply Update 4 instead of following the prescription below. The prescription is kept here only because it might become of some help again, when some partial updates to the shared library support become available.

Installation Prescription

  1. FTP
  2. $ cd <somewhere>
    $ mkdir shared
    $ cd shared
    $ ftp ftp.linuxppc.org
    ....
    Name (....): anonymous
    ....
    Password: <my e-mail address>
    ftp> cd linuxppc/linux-2.0.28/redhat/RPMS/ppc/
    ftp> get glibc-0.961212-1M.ppc.rpm
    ftp> get glibc-devel-0.961212-1M.ppc.rpm
    ftp> get glibc-info-0.961212-1M.ppc.rpm
    ftp> get glibc-static-0.961212-1M.ppc.rpm
    ftp> get libtermcap-2.0.8-2B.ppc.rpm
    ftp> get libtermcap-devel-2.0.8-2B.ppc.rpm
    ftp> get ldconfig-1.8.1-3A.ppc.rpm
    ftp> get gdbm-1.7.3-8A.ppc.rpm
    ftp> get gcc-2.7.2-2H.ppc.rpm
    ftp> get gcc-c++-2.7.2-2H.ppc.rpm
    ftp> get gcc-objc-2.7.2-2H.ppc.rpm
    ftp> get binutils-2.7-1D.ppc.rpm
    ftp> get kernel-headers-2.0.28-1C.ppc.rpm
    ftp> get libg++-2.7.1.4-4E.ppc.rpm
    ftp> get libg++-devel-2.7.1.4-4E.ppc.rpm
    ftp> get NetKit-B-0.08-13B.ppc.rpm
    ftp> get procps-1.01-5B.ppc.rpm
    ftp> bye
    $ ftp isl.cps.msu.edu
    ....
    Name (....): anonymous
    ....
    Password: <my e-mail address>
    ftp> cd pub/penney/mklinux/x-shared
    ftp> get X11R6.3.tar.gz
    ftp> get Xpatch.tar.gz
    ftp> bye
    Getting these might take sometime depending on network trafic. You can use get them from here.

  3. Install Basic Shared Library Support
  4. $ su
    # rpm -i --nodeps --force glibc* libtermcap* ldconfig* gdbm*
    # /sbin/ldconfig -v
    # /sbin/shutdown -r now

  5. Install Compiler Support
  6. $ su
    # rpm -i --force gcc-2* binutils* kernel*
    # rpm -i --force gcc-c++* libg++* gcc-objc*

  7. Install Shared X11 Support
  8. # cd /usr
    # mv X11R6.3 X11R6.3.static
    # rm -rf X11 X11R6 X11R6.1
    # tar -zxpf <somewhere>/X11R6.3.tar.gz
    # ln -s X11R6.3 X11
    # ln -s X11R6.3 X11R6
    # ln -s X11R6.3 X11R6.1
    # cd X11
    # tar -zxpf <somewhere>/Xpatch.tar.gz
    # cat >/etc/ld.so.conf
    /lib
    /usr/lib
    /usr/X11/lib
    /usr/local/lib
    ^D
    # /sbin/ldconfig -v
    The necessary files have been FTPed and stored here.

  9. Fix Up Some Problems
  10. Some applications stopped working after the shared lib installation. In order to make finger work:
    $ su
    # cd /lib
    # ln -s /usr/local/lib/libncurses.so.1.9.9e libncurses.so.2.0
    # rpm -i --force NetKit-B-0.08-13B.ppc.rpm
    In order to make top, uptime, and w work:
    # rpm -i --force procps-1.01-5B.ppc.rpm
    As of Jun 28, you do not need this probably with DR2.1update3.
    See the update records.

Making a Shared Library

  1. Compile
  2. Add -fPIC to CFLAGS. For example, you want in your Makefile something like:

    CFLAGS = -O -fPIC
    .c.o:
    $(CC) -c $(CFLAGS) $<

  3. Link
  4. Add -shared to LDFLAGS. For instance, the following

    SHAREDOBJS = obj1.o obj2.o obj3.o ..... objn.o
    libfoo.so: $(SHAREDOBJS)
    $(CC) -shared -Wl,-soname,libfoo.so -o libfoo.so.1.0 \
    $(SHAREDOBJS)

    creates a shared library file "libfoo.so.1.0" which is to be referred to as "libfoo.so" in dynamic loading.

    Notice that the shared library has to be executable as it must have been so created above.

  5. Install and Register
  6. Install it to a directory that is listed in /etc/ld.so.conf. If not, you can either change the installation destination or add your installation destination to /etc/ld.so.conf like

    # vi /etc/ld.so.conf
    /lib
    /usr/lib
    /usr/X11/lib
    /usr/local/lib
    /usr/lib/gcc-lib/powerpc-unknown-linux/2.7.2.1-ppclinux

    Then do

    # /sbin/ldconfig -v
    /sbin/ldconfig: version 1.8.1
    /lib:
    libpam_misc.so.0 => libpam_misc.so.0.57
    libpam.so.0 => libpam.so.0.57
    libpwdb.so.0 => libpwdb.so.0.54
    libtermcap.so.2 => libtermcap.so.2.0.8
    libutil.so.1 => libutil.so.1
    libresolv.so.2 => libresolv.so.2
    libpthread.so.0 => libpthread.so.0
    libnss_nis.so.1 => libnss_nis.so.1
    libnss_files.so.1 => libnss_files.so.1
    libnss_dns.so.1 => libnss_dns.so.1
    libnss_db.so.1 => libnss_db.so.1
    ......

    This updates /etc/ld.so.cache which lists the available shared libraries on your system.

  7. To See What Registered
  8. To see the contents of the cache file, type

    $ /sbin/ldconfig -p | less
    1 - ELF libz.so.1 => /usr/lib/libz.so.1.0.4
    2 - ELF libz.so.1 => /usr/lib/libz.so.1.0.4
    3 - ELF libutil.so.1 => /lib/libutil.so.1
    4 - ELF libutil.so.1 => /lib/libutil.so.1
    5 - ELF libutil.so.1 => /lib/libutil-1.99.so
    6 - ELF libutil.so.1 => /lib/libutil-1.99.so
    7 - ELF libtk4.2jp.so => /usr/local/lib/libtk4.2jp.so
    8 - ELF libtk4.2.so => /usr/local/lib/libtk4.2.so
    9 - ELF libtk.so => /usr/local/lib/libtk.so
    ......

  9. To Check Dependence
  10. If you want to check which shared libraries a particular application depends upon, try something like

    # ldd /usr/local/bin/xtiff
    libXaw3d.so.6 => /usr/X11/lib/libXaw3d.so.6.1 (0x2aaad000)
    libXmu.so.6 => /usr/X11/lib/libXmu.so.6.0 (0x2ab51000)
    libXt.so.6 => /usr/X11/lib/libXt.so.6.0 (0x2aba7000)
    libXext.so.6 => /usr/X11/lib/libXext.so.6.3 (0x2ac3b000)
    libX11.so.6 => /usr/X11/lib/libX11.so.6.1 (0x2ac8c000)
    libICE.so.6 => /usr/X11/lib/libICE.so.6.3 (0x2ad85000)
    libSM.so.6 => /usr/X11/lib/libSM.so.6.0 (0x2addb000)
    libm.so.6 => /lib/libm.so.6 (0x2ae26000)
    libtiff.so.3 => /usr/local/lib/libtiff.so.3.4.036 (0x2ae89000)
    libc.so.6 => /lib/libc.so.6 (0x2aeff000)
    /lib/ld.so.1 => /lib/ld.so.1 (0x00000000)

    Notice that this command has te be executed as root, if the executable is not readable to ordinary users.


Back to Keisuke Fujii's MkLinux Page
fujiik@jlcuxf.kek.jp May 12, 1997