交叉编译VIM并移植到ARM嵌入式Linux系统

   

原创作品,允许转载,转载时请务必以超链接形式标明文章、作者信息和本声明,否则将追究法律责任。

   众所周知,vim是vi的增强版本,实际体验要比vi好用很多,由于笔者为ARM系统制作的基于busybox的文件系统中只带了vi工具,本文主要介绍怎么移植vim工具到基于busybox的制作的rootfs中。

 

一、编译环境:

    Host机:ubuntu-16.10(64bit)

    Target: arm

    交叉工具链:arm-linux-gnueabi-gcc

    工具包:

        ncurses-5.9.7: https://yunpan.cn/cMkkk9pDiuu7G (提取码:2488)

        vim-7.4.tar.bz2: https://yunpan.cn/cMWcsC5RWptwh (提取码:8d84)

 

二、编译准备

  将下载后的压缩文件放到/home/liangwode/test文件夹,解压缩两个文件。

tar xvzf ncurses-5.9.7.tar.gz
bzip2 -d vim-7.4.tar.bz2
tar xvf vim-7.4.tar

  得到两个目录

vim-74    ncurses-5.9

  

 

三、编译ncurses

    由于vim依赖于libtinfo.so库,而libtinfo.so库的功能都已经编入了ncurses库中,因此需要先编译ncurses,再创建libtinfo.so的符号链接链到ncurses库即可,进入ncurses目录,并配置交叉编译

cd ncurses-5.9
./configure --prefix=/home/test/install_ncurses  --host=arm-linux-gnueabi --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs --without-tests --with-shared

    

    编译并安装ncurses库

make && make install

 

    这样在/home/test/install_ncurses目录下就生成了ncurses的库和头文件等文件 

bin  include  lib  share

    

    进入lib目录,创建littinfo的符号链接

cd lib
ln -s libncurses.so.5 libtinfo.so.5
ln -s libtinfo.so.5 libtinfo.so

  

四、编译vim

  进入vim目录,并配置vim编译环境,其中CPPFLAGS指明了vim编译过程中需要用的libtifo库相关的头文件所在目录,同时LDFLAGS指明了libtinfo库所在的目录。

cd /home/liangwode/test/vim74
./configure --with-features=tiny --disable-gui --without-x --disable-selinux --disable-acl --disable-gpm CPPFLAGS=-I/home/liangwode/test/install_ncurses/include/ncurses LDFLAGS=-L/home/liangwode/test/install_ncurses/lib

   

  开始编译

make CC=arm-linux-gnueabi-gcc

  如果编译中出现 arm-linux-gnueabi/bin/ld: cannot find -ltinfo的错误,那说明tinfo的库制定的路径不对,或者前面的ncuses编译的步骤存在问题。

 

五、移植到目标机

  首先将ncurses库移植到目标机的/usr/lib目录,并创建tinfo库相关的符号链接,笔者将目标机的根文件系统挂载到了/mnt/sysroot目录

cd /home/liangwode/test/install_ncurses
cp -frP lib/* /mnt/sysroot/usr/lib/
cp -frP share/* /mnt/sysroot/usr/share/

/*创建libtinfo.so的符号链接*/
cd /mnt/sysroot/usr/lib
ln -s libncurses.so.5 libtinfo.so.5
ln -s libtinfo.so.5 libtinfo.so

  将vim可执行文件移植到目标机

cd /home/liangwode/test/vim74/src
cp vim /mnt/sysroot/usr/sbin
cd /mnt/sysroot/usr/sbin
chmod 777 vim

  删除vi,并将vi链接到vim

cd /bin
rm -f vi
ln -s /usr/sbin/vim vi

  

  

 

  重启目标机,开机后,输入vim,大功告成

vim


~
~                              VIM - Vi IMproved
~
~                                 version 7.4
~                           by Bram Moolenaar et al.
~                 Vim is open source and freely distributable
~
~                           Sponsor Vim development!
~                type  :help sponsor<Enter>    for information
~
~                type  :q<Enter>               to exit
~                type  :help<Enter>  or  <F1>  for on-line help
~                type  :help version7<Enter>   for version info
~
~                        Running in Vi compatible mode
~                type  :set nocp<Enter>        for Vim defaults
~                type  :help cp-default<Enter> for info on this
~
~
~

  

  

  

 

   

posted @ 2016-08-31 11:52  liangwode  阅读(4381)  评论(0编辑  收藏  举报