Glibc 与 libc 的区别和联系

转http://blog.163.com/dragon_sjl@126/blog/static/100473339201107101517380/

 

1、gcc(gnu collect compiler)是一组编译工具的总称。它主要完成的工作任务是“预处理”和“编译”,以及提供了与编译器紧密相关的运行库的支持,如libgcc_s.so、libstdc++.so等。

Linux系统下的Gcc(GNU C Compiler)是GNU推出的功能强大、性能优越的多平台编译器,是GNU的代表作品之一。gcc是可以在多种硬体平台上编译出可执行程序的超级编译器,其执行效率与一般的编译器相比平均效率要高20%~30%。
Gcc 编译器能将C、C++语言源程序、汇程式化序和目标程序编译、连接成可执行文件,如果没有给出可执行文件的名字,gcc将生成一个名为a.out的文件。 在Linux系统中,可执行文件没有统一的后缀,系统从文件的属性来区分可执行文件和不可执行文件。而gcc则通过后缀来区别输入文件的类别,下面我们来 介绍gcc所遵循的部分约定规则。
.c为后缀的文件,C语言源代码文件;
.a为后缀的文件,是由目标文件构成的档案库文件;
.C,.cc或.cxx 为后缀的文件,是C++源代码文件;
.h为后缀的文件,是程序所包含的头文件;
.i 为后缀的文件,是已经预处理过的C源代码文件;
.ii为后缀的文件,是已经预处理过的C++源代码文件;
.m为后缀的文件,是Objective-C源代码文件;
.o为后缀的文件,是编译后的目标文件;
.s为后缀的文件,是汇编语言源代码文件;
.S为后缀的文件,是经过预编译的汇编语言源代码文件。
Gcc的执行过程
虽然我们称Gcc是C语言的编译器,但使用gcc由C语言源代码文件生成可执行文件的过程不仅仅是编译的过程,而是要经历四个相互关联的步骤∶预处理(也称 预编译,Preprocessing)、编译(Compilation)、汇编(Assembly)和连接(Linking)。
命令gcc首先 调用cpp进行预处理,在预处理过程中,对源代码文件中的文件包含(include)、预编译语句(如宏定义define等)进行分析。接着调用cc1进 行编译,这个阶段根据输入文件生成以.o为后缀的目标文件。汇编过程是针对汇编语言的步骤,调用as进行工作,一般来讲,.S为后缀的汇编语言源代码文件 和汇编、.s为后缀的汇编语言文件经过预编译和汇编之后都生成以.o为后缀的目标文件。当所有的目标文件都生成之后,gcc就调用ld来完成最后的关键性 工作,这个阶段就是连接。在连接阶段,所有的目标文件被安排在可执行程序中的恰当的位置,同时,该程序所调用到的库函数也从各自所在的档案库中连到合适的 地方。

 

2、binutils提供了一系列用来创建、管理和维护二进制目标文件的工具程序,如汇编(as)、连接(ld)、静态库归档(ar)、反汇编 (objdump)、elf结构分析工具(readelf)、无效调试信息和符号的工具(strip)等。通常,binutils与gcc是紧密相集成 的,没有binutils的话,gcc是不能正常工作的。

3、glibc是gnu发布的libc库,也即c运行库。glibc是linux系统中最底层的api(应用程序开发接口),几乎其它任何的运行库 都会倚赖于glibc。glibc除了封装linux操作系统所提供的系统服务外,它本身也提供了许多其它一些必要功能服务的实现,主要的如下:
 (1)string,字符串处理
 (2)signal,信号处理
 (3)dlfcn,管理共享库的动态加载
 (4)direct,文件目录操作
 (5)elf,共享库的动态加载器,也即interpreter
 (6)iconv,不同字符集的编码转换
 (7)inet,socket接口的实现
 (8)intl,国际化,也即gettext的实现
 (9)io
 (10)linuxthreads
 (11)locale,本地化
 (12)login,虚拟终端设备的管理,及系统的安全访问
 (13)malloc,动态内存的分配与管理
 (14)nis
 (15)stdlib,其它基本功能

 

3、glibc和libc都是Linux下的C函数库,那么到底有什么区别呢?
见到Linux下好多的库函数,曾经令我困惑,其实他们是有章可循的。
libc是Linux下的ANSI C的函数库;
glibc是Linux下的GUN C函数库;
ANSI C和GNU C有什么区别呢?
ANSI C是基本的C语言函数库,包含了C语言最基本的库函数。这个库可以根据 头文件划分为 15 个部分,其中包括:字符类型 (<ctype.h>)、错误码 (<errno.h>)、 浮点常数 (<float.h>)、数学常数 (<math.h>)、标准定义 (<stddef.h>)、 标准 I/O (<stdio.h>)、工具函数 (<stdlib.h>)、字符串操作 (<string.h>)、 时间和日期 (<time.h>)、可变参数表 (<stdarg.h>)、信号 (<signal.h>)、 非局部跳转 (<setjmp.h>)、本地信息 (<local.h>)、程序断言 (<assert.h>) 等等。这在其他的C语言的IDE中都是有的。
而GNU C函数库是一种类似于第三方插件的东西,由于Linux是用C语言写的,所以Linux的一些操作是用C语言实现的,所以GNU组织开发了一个C语言的库 用于我们更好的利用C语言开发基于Linux操作系统的程序。其实我们可以把它理解为类似于Qt是一个C++的第三方函数库一样。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1) uClibc is smaller than glibc. We attempt to maintain a glibc compatible interface, allowing applications that compile with glibc to easily compile with uClibc. However, we do not include _everything_ that glibc includes, and therefore some applications may not compile. If this happens to you, please report the failure to the uclibc mailing list, with detailed error messages. //体积小 2) 2) uClibc is much more configurable then glibc. This means that a developer may have compiled uClibc in such a way that significant amounts of functionality have been omitted. 可以根据选择进行配置编译 3) 3) uClibc does not even attempt to ensure binary compatibility across releases. When a new version of uClibc is released, you may or may not need to recompile all your binaries. 4) malloc(0) in glibc returns a valid pointer to something(!?!?) while in uClibc calling malloc(0) returns a NULL. The behavior of malloc(0) is listed as implementation-defined by SuSv3, so both libraries are equally correct. This difference also applies to realloc(NULL, 0). I personally feel glibc's behavior is not particularly safe. To enable glibc behavior, one has to explicitly enable the MALLOC_GLIBC_COMPAT option. 我个人感觉的glibc的行为不是特别安全。启用glibc的行为,人们必须明确启用MALLOC_GLIBC_COMPAT选项。 4) 4.1) glibc's malloc() implementation has behavior that is tunable via the MALLOC_CHECK_ environment variable. This is primarily used to provide extra malloc debugging features. These extended malloc debugging features are not available within uClibc. There are many good malloc debugging libraries available for Linux (dmalloc, electric fence, valgrind, etc) that work much better than the glibc extended malloc debugging. So our omitting this functionality from uClibc is not a great loss. 的glibc的malloc()实现了行为是可调通过MALLOC_CHECK_环境变量。这主要是用来提供额外的malloc调试功能。这些扩展的malloc调试功能都没有可在uClibc的。有很多很好的malloc调试库可用于Linux(dmalloc,电围栏,Valgrind的,等等),其工作多比glibc的扩展malloc调试好。因此,我们忽略了此从uClibc的功能是不是一个巨大的损失。 5) uClibc does not provide a database library (libdb). 6) uClibc does not support NSS (/lib/libnss_*), which allows glibc to easily support various methods of authentication and DNS resolution. uClibc only supports flat password files and shadow password files for storing authentication information. If you need something more complex than this, you can compile and install pam. 7) uClibc's libresolv is only a stub. Some, but not all of the functionality provided by glibc's libresolv is provided internal to uClibc. Other functions are not at all implemented. 8) libnsl provides support for Network Information Service (NIS) which was originally called "Yellow Pages" or "YP", which is an extension of RPC invented by Sun to share Unix password files over the network. I personally think NIS is an evil abomination and should not be used. These days, using ldap is much more effective mechanism for doing the same thing. uClibc provides a stub libnsl, but has no actual support for Network Information Service (NIS). We therefore, also do not provide any of the headers files provided by glibc under /usr/include/rpcsvc. 9) uClibc's locale support is not 100% complete yet. We are working on it. 10) uClibc's math library only supports long double as inlines, and even then the long double support is quite limited. Also, very few of the float math functions are implemented. Stick with double and you should be just fine. 11) uClibc's libcrypt does not support the reentrant crypt_r, setkey_r and encrypt_r, since these are not required by SuSv3. 12) uClibc directly uses kernel types to define most opaque data types. 13) uClibc directly uses the linux kernel's arch specific 'stuct stat'. 14) uClibc's librt library currently lacks all aio routines, all clock routines, and all shm routines (only the timer routines and the mq routines are implemented).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值