The Open Source Swiss Army Knife

/code/c/unix_c/
/code/c/unix_c/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /unix_c 
Permalink: linux_c_lib.htm
Title: add
article options : please login   |  print view

  1. introduction to the 2 types of libraries
  2. which libraries do you have?
  3. creation of libraries
  4. searching
  5. compilation and installation: having two systems on the same computer
  6. nm and symbol checking
  1. introduction to the 2 types of libraries

    library.a ... indicates the name of a static library.

    library.so.version ... indicates a shared library. The stubs are copied from this file and placed in the executable, allowing it to load the library according to ld.so

  2. which libraries do you have?
      For Linux there are three major libc versions:
    • libc-4 ... a.out libc
    • libc-5 ... original ELF libc
    • libc-6 ... GNU libc -- glibc2, e.g. version 2.0.7 (this is the newer library)
    RH linux 5 + .... glibc2
    Debian 2 + ... glibc2
    Caldera OpenLinux 1.3 .... libc5
    Slackware 3.6 ..... libc5

    use the command ldd to show the shared dependencies of an executable (e.g. ldd /usr/bin/X11/term).

    libc is the standard c library and as a result of the ldd command, it will show up as libc.so.5=> /lib/libc.so.5.0.9 The version of the number of the library for which the program was compiled is followed by (points to) the location of that library. For a library to be compatible, the major version must match.

    Can I replace the libc on my Linux system with GNU libc?
    up> You cannot replace any existing libc for Linux with GNU libc. It is binary incompatible and therefore has a different major version. You can, however, install it alongside your existing libc.

    creation of libraries

    gcc -H -c liberr.c -o liberr.o compiles code to object form
    ar rcs liberr.a liberr.o uses the ar utility to form an archive.
    test with nm liberr.a

    the search paths needed for finding libraries

    On my linux RH7.0 system, in /lib directory, libc.so.6 -> libc.2.1.92.so. libc.2.1.92.so is found in /lib too.

      The libraries are in the following directories:
    1. /lib: contains the actual routines of the shared libraries, pointed to by the stubs in /usr/lib
    2. /usr/lib: stubs (for the shared libraries) and the static libraries (*.a) and subdirectories for the programs
    3. /usr/local/lib: other libs not necessary for booting
    4. /usr/X11R6/lib: other libs not necessary for booting

    The order is declared in /etc/ld.so.conf.

    The directive LD_LIBRARY_PATH tells the compiler to look in a special place to find your private libraries; it is an environmental variable. And the -L compiler option? It adds directories to look for header files to the normal search path. Thus, it has nothing to do with the linking stage of compilation, only with the compilation stage.

    If you modify /etc/ld.so.conf you need do ldconfig in order to regenerate.

    compilation and installation of glibc

    evacuating the old files:

    The following is taken from the gnu install file found with glibc tarball.

    None of your old libraries, static or shared, can be used with a different C library major version. For shared libraries this is not a problem, because the filenames are different and the dynamic linker will enforce the restriction. But static libraries have no version information. You have to evacuate all the static libraries in /usr/lib to a safe location.

    The following is taken from the masterfully written piece of prose written in 1995 by Welsh and Kaufmann, Running Linux.

    "When you upgrade a library, you must replace the .a and .so.version files corresponding to the library. The .a file is easy: just copy over it with the new versions. However, you must use some caution when replacing the shared library image, .so.version; most of the programs on the system depend on those images, so youcan't simply delete them or rename them. To put this another way, the symbolic link library.so.major must always point to a valid library image. To accomplish this, first copy the new image file to /lib, and then change the symbolic link to pont to the new file in one step, using ln -sf. "

    We can do this in the following way:

    pwd
    response: /lib
    cp libc.so.5.1 /lib
    ls -l /lib/libc*
    response: shows the library there with a symbolic link pointing to the old libc.so.5.0.9
    ln -sf /lib/libc.so.5.1 /lib/libc.so.5
    this updated the symbolic link, and now, you can remove the old libc.so.5.0.9.
    and be sure to run ldconfig

A way to update your system to have both glib5 and glib6 present is noted at http://huizen.dds.nl/~frodol/glibc/overview.html.

a fresh install like that above is unnecessary if you are not changing the major version of your library, i.e. if not upgrading from libc5 to libc6. compile options to making glibc:
./configure --prefix=/usr glibc faq
reference question 2.2

nm and linking

check the output of nm /root/cvs/modperl-2.0/src/modules/perl/mod_perl.so and it may show something like should be something like U Perl_Ipatchlevel_ptr. which is an unresolved symbol, which gets resolved when libperl.so is loaded. To find out which perl library you have linked against, do: ldd modules/mod_perl.so |grep perl. libperl.so => /home/stas/perl/blead-ithread/lib/5.9.0/i686-linux-thread-multi/CORE/libperl.so (0x4002e000). Now you can check whether the symbol is there. in my case: nm /home/stas/perl/blead-ithread/lib/5.9.0/i686-linux-thread-multi/CORE/libperl.so |grep Perl_Ipatch ::::::::::0011fa41 T Perl_Ipatchlevel_ptr. Chances are that you are linking against the wrong perl library, which will explain the resolving problem.

source: post by stas bekman on the mod perl mailing list (jan 22 2003)


Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top