【整理】libc、glibc和glib的关系

【glibc 和 libc】  

glibc 和 libc 都是 Linux 下的 C 函数库。  
libc 是 Linux 下的 ANSI C 函数库;glibc 是 Linux 下的 GUN C 函数库。  

ANSI C 和 GNU C 有什么区别呢?  

       ANSI C 函数库是基本的 C 语言函数库,包含了 C 语言最基本的库函数。这个库可以根据头文件划分为 15 个部分,其中包括:  
  1. <ctype.h>:包含用来测试某个特征字符的函数的函数原型,以及用来转换大小写字母的函数原型;
  2. <errno.h>:定义用来报告错误条件的宏;
  3. <float.h>:包含系统的浮点数大小限制;
  4. <math.h>:包含数学库函数的函数原型;
  5. <stddef.h>:包含执行某些计算 C 所用的常见的函数定义;
  6. <stdio.h>:包含标准输入输出库函数的函数原型,以及他们所用的信息;
  7. <stdlib.h>:包含数字转换到文本,以及文本转换到数字的函数原型,还有内存分配、随机数字以及其他实用函数的函数原型;
  8. <string.h>:包含字符串处理函数的函数原型;
  9. <time.h>:包含时间和日期操作的函数原型和类型;
  10. <stdarg.h>:包含函数原型和宏,用于处理未知数值和类型的函数的参数列表;
  11. <signal.h>:包含函数原型和宏,用于处理程序执行期间可能出现的各种条件;
  12. <setjmp.h>:包含可以绕过一般函数调用并返回序列的函数的原型,即非局部跳转;
  13. <locale.h>:包含函数原型和其他信息,使程序可以针对所运行的地区进行修改。
  14. 地区的表示方法可以使计算机系统处理不同的数据表达约定,如全世界的日期、时间、美元数和大数字;
  15. <assert.h>:包含宏和信息,用于进行诊断,帮助程序调试。
上述库函数在其各种支持 C 语言的 IDE 中都是有的。  

       GNU C 函数库是一种类似于第三方插件的东西。由于 Linux 是用 C 语言写的,所以 Linux 的一些操作是用 C 语言实现的,因此,GUN 组织开发了一个 C 语言的库 以便让我们更好的利用 C 语言开发基于 Linux 操作系统的程序。   不过现在的不同的 Linux 的发行版本对这两个函数库有不同的处理方法,有的可能已经集成在同一个库里了。  

查看当前系统的 glibc 版本的方法:  
1.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root @Betty ~]# /lib/libc.so.6
GNU C Library stable release version 2.5, by Roland McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This isfreesoftware; see thesourceforcopying conditions.
There is NO warranty; not evenforMERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-52).
Compiled on a Linux 2.6.9 system on 2013-01-08.
Available extensions:
        The C stubs add-on version 2.1.2.
        cryptadd-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        GNU libio by Per Bothner
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
        RT using linux kernel aio
Thread-localstorage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
[root @Betty ~]#
2.  
?
1
2
3
4
5
6
7
[root @Betty ~]# ldd  --version
ldd (GNU libc) 2.5
Copyright (C) 2006 Free Software Foundation, Inc.
This isfreesoftware; see thesourceforcopying conditions.  There is NO
warranty; not evenforMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
[root @Betty ~]#


【glibc 和 glib】  

      错误观点:glib 前面有个 "g" ,所以认为 glib 是 GNU 的东东;同时认为 glibc 是 glib 的一个子集。  

      其实,glib 和 glibc 基本上没有太大联系,可能唯一的共同点就是,其都是 C 编程需要调用的库而已。  
glib 是 Gtk+ 库和 Gnome 的基础。glib 可以在多个平台下使用,比如 Linux、Unix、Windows 等。glib 为许多标准的、常用的 C 语言结构提供了相应的替代物。  


【官方说明】

Glib

GLib is a general-purpose utility library, which provides many useful data types, macros, type conversions, string utilities, file utilities, a main loop abstraction, and so on. It works on many UNIX-like platforms, Windows, OS/2 and BeOS. GLib is released under the GNU Library General Public License (GNU LGPL).
The general policy of GLib is that all functions are invisibly threadsafe with the exception of data structure manipulation functions, where, if you have two threads manipulating the same data structure, they must use a lock to synchronize their operation.
GLib is the low-level core library that forms the basis for projects such as GTK+ and GNOME. It provides data structure handling for C, portability wrappers, and interfaces for such runtime functionality as an event loop, threads, dynamic loading, and an object system. 

Glibc 
Overview: 
Any Unix-like operating system needs a C library: the library which defines the ``system calls'' and other basic facilities such as open, malloc, printf, exit... 
The GNU C Library is used as the C library in the GNU systems and most systems with the Linux kernel.
Project Goals:  
The GNU C Library is primarily designed to be a portable and high performance C library. It follows all relevant standards including ISO C11 and POSIX.1-2008. It is also internationalized and has one of the most complete internationalization interfaces known.
History: 
The history of Unix and various standards determine much of the interface of the C library. In general the GNU C Library supports the ISO C and POSIX standards. We also try to support the features of popular Unix variants (including BSD and System V) when those do not conflict with the standards. Different compatibility modes (selectable when you compile an application) allow the peaceful coexistence of compatibility support for different varieties of Unix. 

【其他说法】  

libc 实际上是一个泛指。凡是符合实现了 C 标准规定的内容,都是一种 libc 。
glibc 是 GNU 组织对 libc 的一种实现。它是 unix/linux 的根基之一。
微软也有自己的 libc 实现,叫 msvcrt 。
嵌入式行业里还常用 uClibc ,是一个迷你版的 libc 。


转载于:https://my.oschina.net/u/1990683/blog/298417

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值