uClibc 与 Glibc 你所不知道的区别

        CC的标准库,就是glibc这个库,里面有GCC各种标准函数的实现,还有各种unix系的函数在里面。 
        当初创建uclinux的时候,需要一个能编译比较小体积的目标文件的便宜器,这个时候就有人写了一个uc-libc库,这个库可以说是uclinux上的一个glibc移植,但是还是有很多函数没有实现,所以人们只能勉强用它来在uclinux上写程序。
        后来,有牛人又写了uclibc,这个是真正意义上的瘦身过后的glibc,完成了很多以前uc-libc不支持的函数。
        本人觉得最有价值的就是uclibc实现了pthread系列函数,以前用uc-libc只能用fork+exec来完成的多线程功能。uclibc现在也不只是用在嵌入式系统上面,一些人也喜欢在标准平台使用它来编译一些程序。 
        下面转载一家外国网站的文章,英文不好请采用google翻译。

                uClibc and Glibc are not the same -- there are a number of differences which 
may or may not cause you problems. This document attempts to list these 
differences and, when completed, will contain a full list of all relevant 
differences. 


                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) 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) 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. 

                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. 

                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).

      赠人玫瑰,手有余香。文章有用,敬请转载。我是米洛QQ573581882,我为自己代言。
<think>嗯,用户问的是如何在海思编译链中切换uClibcglibc。我需要先回忆一下海思的SDK结构,可能涉及到工具链的选择配置。根据之前的引用,用户提供的引用中提到了Buildroot支持同的C库,但ARMCortex-M只能用uClibc-ng,而海思的芯片可能属于同的架构。用户之前的问题中提到海思的编译链,比如arm-hisiv300-linux-gcc这样的工具链,可能同的工具链版本对应同的C库。比如,v300可能默认使用uClibc,而新版本可能支持glibc。需要检查工具链的配置,或者SDK中的设置。引用3提到查看板子上的uclibc版本,可以通过检查/lib目录下的文件来确定当前使用的库版本,这可能对切换有帮助。 另外,引用2指出uClibc用于嵌入式,glibc用于桌面,而eglibcglibc的嵌入式版本。所以切换时可能需要选择对应的工具链版本或者重新配置Buildroot。海思SDK可能有同的配置选项,需要修改Makefile或config文件,比如在osdrv目录下的配置,或者工具链的指定路径。用户提供的引用4提到修改Makefile中的CC变量库路径,这可能涉及到指定同的C库路径。例如,在编译工具链时,可能需要指定--with-sysroot指向glibcuClibc的库。同时,引用5中的编译错误可能涉及到配置选项未定义,切换C库时需要注意内核配置是否匹配,比如某些宏定义可能需要调整。步骤可能包括:1.确定当前工具链支持的C库;2.修改Buildroot或SDK配置选择C库类型;3.重新编译工具链或SDK;4.验证库版本是否匹配。需要详细说明每一步的具体操作,比如如何修改配置文件,如何指定库路径,如何处理依赖等。 用户可能遇到的常见问题包括:工具链兼容、库版本匹配、编译错误等。需要提醒用户检查版本,确保内核用户空间库一致,以及如何验证切换后的结果,例如使用ldd或查看库文件。</think>### 海思编译链中uClibcglibc的切换方法 #### 一、核心步骤 1. **确认工具链支持** - 海思官方工具链(如`arm-hisiv300-linux-gcc`)通常默认绑定特定C库,需通过工具链名称或文档确认是否支持切换[^2]。 - 查看当前工具链的C库版本: ```bash # 查看动态链接器路径 $ arm-hisiv300-linux-readelf -l <可执行文件> | grep "INTERP" # 或直接检查工具链的lib目录 $ ls /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/lib ``` 2. **修改Buildroot配置** - 若使用Buildroot构建系统,需在`make menuconfig`中修改C库类型: ```text Toolchain → C library → 选择glibc/uClibc-ng ``` 但需注意:**海思某些芯片(如Cortex-M核)仅支持uClibc**[^1]。 3. **调整SDK编译参数** - 在海思SDK的`osdrv/Makefile`或子模块配置中,指定C库路径: ```makefile # 示例:指定glibc头文件路径 CFLAGS += -I/opt/hisi-glibc/usr/include LDFLAGS += -L/opt/hisi-glibc/usr/lib ``` - 若需静态链接,添加`-static`标志: ```bash arm-hisiv300-linux-gcc -static main.c -o output ``` #### 二、验证调试 1. **检查库版本兼容性** - 在目标设备上运行: ```bash $ ls /lib/ld-* # 查看动态加载器版本[^3] $ ldd <应用程序> # 检查动态库依赖(需设备支持) ``` 2. **处理常见问题** - **内核C库匹配**:若出现`undefined reference`错误,需同步内核头文件C库版本[^5]。 - **存储空间足**:glibc镜像可能占用$16\text{MB}$以上Flash,需调整分区大小。 #### 三、场景建议 | **操作** | **适用场景** | |------------------------|------------------------------------------| | **切换至uClibc** | 资源受限设备、需快速启动(如IPC摄像头) | | **切换至glibc** | 需运行复杂应用(如Python解释器) | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值