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
  4. MkLinux DR3 comes with a full shared library support, so that you can benefit from them as soon as you install DR3. If you haven't, you should upgrade to DR3, 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/redhat/RPMS/ppc/
    ftp> get glibc-0.961212-1l.ppc.rpm
    ftp> get glibc-devel-0.961212-1l.ppc.rpm
    ftp> get glibc-info-0.961212-1l.ppc.rpm
    ftp> get glibc-static-0.961212-1l.ppc.rpm
    ftp> get libg++-2.8.1.980306-1c.ppc.rpm
    ftp> get libg++-devel-2.8.1.980306-1c.ppc.rpm
    ftp> get egcs-1.0-2e.ppc.rpm
    ftp> get egcs-as-gcc-1.0-2e.ppc.rpm
    ftp> get egcs-c++-1.0-2e.ppc.rpm
    ftp> get egcs-fixes-1-1.noarch.rpm
    ftp> get egcs-g77-1.0-2e.ppc.rpm
    ftp> get binutils-2.9.1-1a.ppc.rpm
    ftp> get kernel-headers-2.1.24-1.ppc.rpm
    ftp> bye

    Try other directories in the same FTP site, if you don't find some of the above rpms: RedHat/updates/RPMS/ppc/ or RedHat/RPMS/.

  3. Install Basic Shared Library Support
  4. $ su
    # rpm -Uvh glibc*
    # rpm -Uvh libg++*
    # /sbin/shutdown -r now

  5. Install Compiler Support
  6. $ su
    # rpm -Uvh binutils*
    # rpm -Uvh egcs-*
    # rpm -Uvh kernel*

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
    /usr/local/lib
    /opt/kde/lib
    /usr/X11R6/lib
    /opt/ivtools/lib

    This adds "/opt/ivtools/lib" as a possible directory containing shared libraries in addition to "/usr/local/lib", "/opt/kde/lib", and "/usr/X11R6/lib". Note that "/lib" and "/usr/lib" are implicit and do not have to be listed in /etc/ld.so.conf.

    Then do

    # /sbin/ldconfig -v
    /sbin/ldconfig: version 970402
    /usr/local/lib:
    libkpathsea.so.3.2.0 => libkpathsea.so.3.2.0
    libf2c.so => libf2c.so.0.5.19
    libtk4.2jp.so => libtk4.2jp.so
    libtcl7.6jp.so => libtcl7.6jp.so
    libVFlib.so.2 => libVFlib.so.2.22
    libwnn.so.1.0 => libwnn.so.1.0.0
    libjd.so.1.0 => libjd.so.1.0.0
    ......

    This updates /etc/ld.so.cache which lists the available shared libraries on your system and allows the dynamic loader to use new liabraries.

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

    $ /sbin/ldconfig -p | less
    libz.so.1 (ELF) => /usr/lib/libz.so.1
    libz.so (ELF) => /usr/lib/libz.so
    libwnn.so.1.0 (ELF) => /usr/local/lib/libwnn.so.1.0
    libwnn.so (ELF) => /usr/local/lib/libwnn.so
    libuulib.so.0 (ELF) => /opt/kde/lib/libuulib.so.0
    libuulib.so (ELF) => /opt/kde/lib/libuulib.so
    libuuid.so.1 (ELF) => /lib/libuuid.so.1
    libutil.so.1 (ELF) => /lib/libutil.so.1
    libutil.so (ELF) => /usr/lib/libutil.so
    ......

  9. To Check Soname
  10. $ objdump -p /usr/lib/libz.so.1.1.2 | grep SONAME
    SONAME libz.so.1

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

    $ ldd /opt/netscape/netscape
    libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x2aaae000)
    libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x2aafa000)
    libXmu.so.6 => /usr/X11R6/lib/libXmu.so.6 (0x2ab51000)
    libXpm.so.4 => /usr/X11R6/lib/libXpm.so.4 (0x2aba8000)
    libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x2abf9000)
    libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x2ac49000)
    libdl.so.2 => /lib/libdl.so.2 (0x2ad4d000)
    libc.so.6 => /lib/libc.so.6 (0x2ad91000)
    /lib/ld.so.1 => /lib/ld.so.1 (0x00000000)
    libg++.so.27 => /usr/lib/libg++.so.27 (0x2ae90000)
    libstdc++.so.27 => /usr/lib/libstdc++.so.27 (0x2af1e000)
    libm.so.6 => /lib/libm.so.6 (0x2afb6000)

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


Back to Keisuke Fujii's MkLinux Page
fujiik@jlcuxf.kek.jp Aug 1, 1998