Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3965084
  • 博文数量: 366
  • 博客积分: 9916
  • 博客等级: 中将
  • 技术积分: 7195
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-29 23:27
个人简介

简单!

文章分类

全部博文(366)

文章存档

2013年(51)

2012年(269)

2011年(46)

分类: 嵌入式

2012-04-18 23:09:51

        编译libiconv库之后,发现库文件有1M多,经过压缩之后还是有600~700K,对于flash很小的嵌入式系统来说,简直就是致命的,而且该库中的很多编码方式并不是我们所需要的。如果自己重新写编码转换的话,又很耗时间。个人认为裁减libiconv库是一个不错的选择,google了一下,发现根本没有关于裁减这个库的资料。所以,尝试着作了裁减。以下是我操作的相关步骤,供有需要的朋友参考。

1、从官网上下载libiconv库,最新版本的下载地址:

2、解压下载的库文件
# tar -xzvf libiconv-1.14.tar.gz

3、修改相应的三个文件(converters.h,encodings.def,aliases.h)即可,都位于libiconv-1.14/lib目录下,以下以删减iso2022_kr编码库为例:
    a.去除converters.h中定义的头文件
    #if 0
    #include "iso2022_kr.h"
    #endif
    
    在终端执行./configure & make,出现以下错误:
    make[1]: Entering directory `/root/example/libiconv-1.14/lib'
/bin/sh ../libtool --mode=compile gcc -I. -I. -I../include -I./../include -I.. -I./..  -g -O2 -fvisibility=hidden -DLIBDIR=\"/usr/local/lib\" -DBUILDING_LIBICONV -DBUILDING_DLL -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"/usr/local/lib\" -DNO_XMALLOC -Dset_relocation_prefix=libiconv_set_relocation_prefix -Drelocate=libiconv_relocate -DHAVE_CONFIG_H -c ./iconv.c
libtool: compile:  gcc -I. -I. -I../include -I./../include -I.. -I./.. -g -O2 -fvisibility=hidden -DLIBDIR=\"/usr/local/lib\" -DBUILDING_LIBICONV -DBUILDING_DLL -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"/usr/local/lib\" -DNO_XMALLOC -Dset_relocation_prefix=libiconv_set_relocation_prefix -Drelocate=libiconv_relocate -DHAVE_CONFIG_H -c ./iconv.c  -fPIC -DPIC -o .libs/iconv.o
In file included from ./iconv.c:112:
./encodings.def:1024: error: 'iso2022_kr_mbtowc' undeclared here (not in a function)
./encodings.def:1024: error: 'iso2022_kr_wctomb' undeclared here (not in a function)
./encodings.def:1024: error: 'iso2022_kr_reset' undeclared here (not in a function)
make[1]: *** [iconv.lo] Error 1
make[1]: Leaving directory `/root/example/libiconv-1.14/lib'

    b.接着修改encodings.def文件,屏蔽该文件中的以下内容
    #if 0
    DEFENCODING(( "ISO-2022-KR",            /* IANA, RFC 1557 */
                  "csISO2022KR",            /* IANA */
                /*"ISO2022KR",                 JDK 1.1 */
                ),
                iso2022_kr,
                { iso2022_kr_mbtowc, NULL },  { iso2022_kr_wctomb, iso2022_kr_reset })
    #endif

    在终端中继续执行make,看看又有什么错误会出现。
    cd lib && make all
make[1]: Entering directory `/root/example/libiconv-1.14/lib'
/bin/sh ../libtool --mode=compile gcc -I. -I. -I../include -I./../include -I.. -I./..  -g -O2 -fvisibility=hidden -DLIBDIR=\"/usr/local/lib\" -DBUILDING_LIBICONV -DBUILDING_DLL -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"/usr/local/lib\" -DNO_XMALLOC -Dset_relocation_prefix=libiconv_set_relocation_prefix -Drelocate=libiconv_relocate -DHAVE_CONFIG_H -c ./iconv.c
libtool: compile:  gcc -I. -I. -I../include -I./../include -I.. -I./.. -g -O2 -fvisibility=hidden -DLIBDIR=\"/usr/local/lib\" -DBUILDING_LIBICONV -DBUILDING_DLL -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"/usr/local/lib\" -DNO_XMALLOC -Dset_relocation_prefix=libiconv_set_relocation_prefix -Drelocate=libiconv_relocate -DHAVE_CONFIG_H -c ./iconv.c  -fPIC -DPIC -o .libs/iconv.o
In file included from ./iconv.c:154:
lib/aliases.gperf:356: error: 'ei_iso2022_kr' undeclared here (not in a function)
make[1]: *** [iconv.lo] Error 1
make[1]: Leaving directory `/root/example/libiconv-1.14/lib'

    c.最后,修改aliases.h文件(这步比较关键,如果不细心的话,可能在实际应用的时候会找不到你所需要的编码,造成不必要的麻烦)。在该文件中,找到有ei_iso2022_kr的地方,作如下修改:
    #if 0
    #line 355 "lib/aliases.gperf"
        {(int)(long)&((struct stringpool_t *)0)->stringpool_str362, ei_iso2022_kr},
    #else
        {-1},
    #endif

    #if 0
    #line 356 "lib/aliases.gperf"
        {(int)(long)&((struct stringpool_t *)0)->stringpool_str334, ei_iso2022_kr},
    #else
        {-1},
    #endif

    再一次make的时候,可以发现没有其它任何的错误。

4、经过裁减后,库可以成功编译出来了,但整体的编译可能还是存在一些问题,原因是你删除了相关的编码方式,而那些程序恰好使用到了它。以下是我遇到的一个问题的解决方法:
    问题:make进入libiconv-1.14/src目录不能编译。
    解决方法:不编译此目录。由于这里面的Makefile是根据Makefile.in文件生成的,所以直接修改Makefile.in
    屏蔽以下两句
    all : iconv_no_i18n$(EXEEXT) iconv.@OBJEXT@ $(OBJECTS_RES_@WOE32@)
    test `ls -ld . | sed -e 's/^d\(.........\).*/\1/'` = rwxrwxrwx || chmod 777 .
    新增
    all:

    如果只是删减一个的话,看不出有什么太大的变化,可以删除多个试试!
阅读(4432) | 评论(1) | 转发(4) |
给主人留下些什么吧!~~

protheschildren2012-05-05 16:48:11

收藏先,