glibc与uclibc的区别


前言

什么是 ANSI C?
ANSI C 是基本的C语言函数库,包含了C语言最基本的库函数。
1983年,美国国家标准协会(ANSI)组成了一个委员会,X3J11,为了创立 C 的一套标准。经过漫长而艰苦的过程,该标准于1989年完成,这个版本的语言经常被称作ANSI C,或有时称为C89(为了区别C99)。在1990年,ANSI C标准(带有一些小改动)被美国国家标准协会(ANSI)采纳为ISO/IEC 9899:1990。这个版本有时候称为C90或者ISO C。综上,ANSI C、ISO C、C89、C90其实是同一种标准。


一、Glibc 是什么?

glibc 和 libc 都是 Linux 下的C函数库:

  1. libc 是 Linux 下的 ANSI C 的函数库;
  2. GNU C 是一种 ANSI C 的扩展实现;
  3. glibc 是 Linux 下的 GUN C 的函数库。

Glibc 常应用于桌面和服务器的 GNU/Linux 类的系统,都是用C语言标准库。
其实现了常见的C库的函数,支持很多种系统平台,功能很全,但是也相对比较臃肿和庞大。

二、uClibc 是什么?

uClibc 是一个小型的C标准库,主要用于嵌入式 Linux 系统。
最初是为了支持 uClinux 而开发(注:uClinux不支持MMU),因此比较适用于微处理器中。而此处的u意思是μ,Micro,微小的意思。
uClibc 比一般用于 Linux 发行版的C库 GNU C Library (glibc) 要小得多, uClibc 专注于嵌入式Linux。很多功能可以根据空间需求进行取舍。

uClibc的特点:
(1)uClibc比glibc要小很多。
(2)uClibc是独立的,为了应用于嵌入式系统中,完全重新实现出来的。和glibc在源码结构和二进制上,都不兼容。
(3)uClibc在可配置性上比glibc要好。

三、Glibc, uClibc 的区别与联系

  1. 写程序,需要用到很多c语言的库函数。所有的库函数加起来,就是对应的C语言(标准)函数库。
  2. 目前在普通 GNU/Linux 系统中所用的C语言标准库,叫做glibc。其功能很全,函数很多,但是代码太多,编译出来的函数库的大小也很大,即资源占用也很多。
  3. 而嵌入式系统中,也需要C语言写代码实现特定功能,也需要用到C语言函数库,但是由于嵌入式系统中,一般资源比较有限,所以不适合直接使用(太占用资源的)glibc。
  4. 所以有人就又(没有参考glibc,而是从头开始写)重新实现了一个适用于嵌入式系统的,代码量不是很大的,资源占用相对较少的,C语言函数库,叫做uClibc。注:uClibc不支持MMU(内存管理单元)。

四、Glibc, uClibc 的使用注意事项

  1. 虽然 uClibc 和 Glibc 在已有的接口上是兼容的,但是 uClibc 并没有包括Glibc 中的所有接口实现,因此有些应用可能在 uClibc 中不能编译。

  2. uClibc 并不能保证发布的库二进制兼容旧版本 uClibc 库。当一个新的版本uClibc 库被发布,则可能需要也可能不需要重新编译应用程序。

  3. 在 Glibc 中调用 malloc(0),将返回一个有效的指针,然而在 uClibc 中调用 malloc(0),则返回NULL指针。根据在 SuSv3 中关于 malloc(0) 的行为的定义,两个库的实现都是正确的。对于调用 relloc(NULL,0),两个库的实现也不同。个人感觉 Glibc 的如此实现不是特别安全。Glibc 中 malloc 的实现可以通过 MALLOC_CHECK_ 环境变量调节。这个方法主要用于 malloc 调试。这些扩展的 malloc 调试特性在 uClibc 中是不可用的。在 Linux 上有许多有些的 malloc 调试功能的库(如:dmalloc, electric fence, valgrind等)比 Glibc 中的扩展的 malloc 调试功能更好用。因此 uClibc 中去掉这些功能特性并不会有多大损失。

  4. uClibc 没有提供用于数据接口的库 (libdb)。

  5. uClibc 不支持 NSS(/lib/libnss_*),在这方面 Glibc 更容易支持不同方式的认证和 DNS 解析。uClibc 仅仅支持采用 flat 口令文件或者 shadow 口令文件存储授权信息。如果需要比这些更复杂的的授权,可以编译安装 pam。

  6. uClibc 中的 libresolv 库仅仅是一个桩。Glibc 的 libresolv 库中的部分并不是全部的功能 uClibc 都提供,许多函数都没有实现。

  7. 提供网络信息服务支持(NIS)libnsl库(最初被称为黄页YP),被SUN扩展为发明为RPC并用于网络共享Unix口令文件。个人认为NIS是一个令人厌恶的东西并应该使用。因此,在实现相同的功能情况下采用ldap比NIS更有效。uClibc虽然提供一个桩libnsl,但并不支持NIS。我们因此也不提供在Glibc下提供的位于/usr/include/rpcsvc里的头文件。

  8. uClibc 的区域支持并不是100%的完全。正在这方面努力

  9. uClibc 的数据功能函数库内部仅仅支持 long double,设置对于 long double 的支持也是非常有限。与此对应的只实现了较少的数学函数。如果应用程序采用 double 类型,则会程序会运行得较好。

  10. uClibc 的 libcrpt 库不支持可重入 crypt_r, setkey_r 和 encrypt_r,因为这些也不是 SuSv3 所规定的。

  11. uClibc 直接采用内核的数据类型去定义大多数透明的数据类型。

  12. uClibc 支持采用 Linux 内核结构特有的结构体 “struct stat”。

  13. uClibc 的运行时库 librt 当前缺少 aio 接口、全部的时钟接口和共享内存接口(仅仅实现定时器接口和消息队列接口)

总结:

可以简单的理解为:
glibc,uClibc 都是C语言函数库:

  1. uClibc 是专注于嵌入式系统的;
  2. glibc 是专注于桌面/服务器系统的。

参考文献

  1. https://blog.csdn.net/hemmingway/article/details/38870811
  2. https://developer.aliyun.com/article/48434
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

积步千里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值