Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26907
  • 博文数量: 6
  • 博客积分: 240
  • 博客等级: 二等列兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-09 22:54
文章分类
文章存档

2011年(1)

2010年(2)

2009年(3)

我的朋友

分类: LINUX

2009-05-09 22:44:51

6.2 Libraries

In Chapter 4 we discussed how to build, install, and use the GNU C library and its alternatives for application development. Here, we will discuss how to install those same libraries on the target's root filesystem so that they can be used at runtime by the applications we develop. We will not discuss diet libc, because it is mainly used as a static library.

第4章,我们讨论了如何建立,安装和使用的GNU C库及其应用开发的替代品。在这里,我们将讨论如何在目标根文件系统安装这些库,使它们能够被我们开发的应用程序在运行时使用。我们将不讨论diet libc,因为它主要是用来作为静态库。

6.2.1 glibc

As I said earlier, the glibc package contains a number of libraries. You can see the entire list of libraries installed during the package's build process by looking at your ${TARGET_PREFIX}/lib directory. This directory contains mainly four types of files:

Actual shared libraries

    These files' names are formatted as libLIBRARY_NAME-GLIBC_VERSION.so, where LIBRARY_NAME is the name of the library and GLIBC_VERSION is the version of the glibc package you are using. The name of the math library for glibc 2.2.3 is libm-2.2.3.so.
Major revision version symbolic links

    Major revision versions do not follow the same numbering as the actual glibc version. The major revision version for the actual shared C library in glibc 2.2.3, libc-2.2.3.so, is 6. In contrast, the major revision version for libdl-2.2.3.so is 2. The names of the symbolic links for the major revision version are formatted as libLIBRARY_NAME.so.MAJOR_REVISION_VERSION, where MAJOR_REVISION_VERSION is the major revision version of the library. For the actual C library, for instance, the symbolic link is libc.so.6. For libdl, it is libdl.so.2. Once a program has been linked to a library, it will refer to this symbolic link. At startup, the loader will therefore look for this file before loading the program.
Version-independent symbolic links to the major revision version symbolic links

    The role of these links is to provide a universal entry for all the programs that need to link with a particular library, regardless of the actual major revision or the version of glibc involved. These symbolic links are typically formatted as libLIBRARY_NAME.so. For example, libm.so points to libm.so.6, which itself points to the actual shared library, libm-2.2.3.so. The only exception to this is libc.so, which, as I said in Chapter 4, is a link script. The version-independent symbolic link is the one used when linking programs.
Static library archives

    These archives are used by applications that choose to link statically with a library. The names of these archives are formatted as libLIBRARY_NAME.a. The static archive for libdl, for instance, is libdl.a.

正如我前面所说,与glibc包包含了一些库。通过观察你的${TARGET_PREFIX}/lib目录,在包的编译过程中,你可以看到整个被安装的库列表。这个目录主要包含四种类型的文件:

Actual shared libraries(实际的共享库)
      这些文件的名字被格式化为libLIBRARY_NAME-GLIBC_VERSION.so. LIBRARY_NAME是库的名字,GLIBC_VERSION是你使用的glibc包的版本号。例如,glibc 2.2.3使用的math库名称是libm-2.2.3.so。

Major revision version symbolic links(主要修订版本符号链接)
      主要修订版本不与实际的glibc的版本一样遵循相同的编号。实际共享C库glibc 2.2.3,libc-2.2.3.so主要修订版本是6 ,libdl-2.2.3.so主要修订版本是2.主要修订版本符号链接的名字格式化为libLIBRARY_NAME.so.MAJOR_REVISION_VERSION, MAJOR_REVISION_VERSION是库的主要修订版本。例如,实际C库的符号链接是libc.so.6,而libdl是libdl.so.2。一旦程序已链接到一个库,它会参照此符号链接。启动时,装载器首先寻找这个文件,然后加载该程序。

Version-independent symbolic links to the major revision version symbolic links
(版本无关的符号链接的主要修订版本符号链接)
      这些链接为需要链接到特别库的所有程序提供了一个普遍的入口。无论实际的主修订或调用的glic的版本。这些符号链接通常格式化为libLIBRARY_NAME.so。例如, libm.so指向libm.so.6 ,而libm.so.6指向实际共享库libm-2.2.3.so。唯一的例外是libc.so,在第4章讲过,是一个链接脚本。版本无关的符号链接是一个连接时使用的程序。

Static library archives(静态库档案)
      应用程序选择静态链接库时使用这些档案。档案名字格式化为libLIBRARY_NAME.a.例如,静态档案libdl的名字是libdl.a.


You will also find some other types of files in ${TARGET_PREFIX}/lib, such as crti.o and crt1.o, but you will not need to copy these to your target's root filesystem.

Out of the four types of files described above, we will need only two for each library: the actual shared libraries and the major revision version symbolic links. The two other file types are needed only when linking executables and are not required for the runtime operation of our applications.

In addition to the library files, we will need to copy the dynamic linker and its symbolic link. The dynamic linker itself follows the naming convention of the various glibc libraries, and is usually called ld-GLIBC_VERSION.so. In what is probably one of the most bizarre aspects of the GNU toolchain, however, the name of the symbolic link to the dynamic linker depends on the architecture for which the toolchain has been built. If the toolchain is built for the i386, the ARM, the SuperH, or the m68k, the symbolic link to the dynamic linker is usually called ld-linux.so.MAJOR_REVISION_VERSION. If the toolchain is built for the MIPS or the PowerPC, the symbolic link to the dynamic linker is usually called ld.so.MAJOR_REVISION_VERSION.

你也可以在${TARGET_PREFIX}/lib目录下找到其它类型的文件,比如crti.o和crtl.o,但是你不需要拷贝这些文件到目标根文件系统中。

上面描述的四种类型文件,我们只需要两种:实际共享库和主修订版本符号链接。其它两种类型文件只在链接可执行文件是需要,在应用程序运行是不需要。

除了库文件,我们将需要复制动态链接器和它的符号链接。动态链接器遵循glibc库的命名公约,通常称为ld-GLIBC_VERSION.so.GNU工具链可能的最奇怪的方面,动态链器的符号链接的名字依赖于工具链已编译的架构。如果工具链是i386,arm,SuperH,m68k,动态链接器的符号链接通常命名为ld-linux.so.MAJOR_REVISION_VERSION. 如果工具链是mips或PowerPC,通常命名为ld.so.MAJOR_REVISION_VERSION.

Before we actually copy any glibc component to the target's root filesystem, however, we need to select the glibc components required for our applications. Table 6-2 provides the description of all the components in glibc and provides inclusion guidelines for each component. In addition to my guidelines, you will need to evaluate which components your programs need, depending on their linking.

See the glibc manual for a complete description of the facilities provided.

Table 6-2. Library components in glibc and root filesystem inclusion guidelines

Library component

Content

Inclusion guidelines

ld

Dynamic linker.

Compulsory.

libBrokenLocale

Fixup routines to get applications with broken locale features torun. Overrides application defaults through preloading. (Need to useLD_PRELOAD).

Rarely used.

libSegFault

Routines for catching segmentation faults and doing backtraces.

Rarely used.

libanl

Asynchronous name lookup routines.

Rarely used.

libc

Main C library routines.

Compulsory.

libcrypt

Cryptography routines.

Required for most applications involved in authentication.

libdl

Routines for loading shared objects dynamically.

Required for applications that use functions such asdlopen( ).

libm

Math routines.

Required for math functions.

libmemusage

Routines for heap and stack memory profiling.

Rarely used.

libnsl

NIS network services library routines.

Rarely used.

libnss_compat

Name Switch Service (NSS) compatibility routines for NIS.

Loaded automatically by the glibc NSS.

libnss_dns

NSS routines for DNS.

Loaded automatically by the glibc NSS.

libnss_files

NSS routines for file lookups.

Loaded automatically by the glibc NSS.

libnss_hesiod

NSS routines for Hesiod name service.

Loaded automatically by the glibc NSS.

libnss_nis

NSS routines for NIS.

Loaded automatically by the glibc NSS.

libnss_nisplus

NSS routines for NIS plus.

Loaded automatically by the glibc NSS.

libpcprofile

Program counter profiling routines.

Rarely used.

libpthread

Posix 1003.1c threads routines for Linux.

Required for threads programming.

libresolv

Name resolver routines.

Required for name resolution.

librt

Asynchronous I/O routines.

Rarely used.

libthread_db

Thread debugging routines.

Loaded automatically by gdb when debuggingthreaded applications. Never actually linked to by any application.

libutil

Login routines, part of user accounting database.

Required for terminal connection management.

阅读(1146) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~