操作系统: Ubuntu9.04 redhat enterprise linux 5
开发板: 博创2410s
交叉编译工具: arm-linux-gcc-4.1.1
ncurses版本: ncurses-5.5
1、下载ncurses库ncurses-5.5.tar.gz到~/arm2410s下并解压
lingd@ubuntu:~/arm2410s$ tar -zxvf ncurses-5.5.tar.gz
2、配置ncurses
将ncurses库安装在~/arm2410s/ncurses目录下
lingd@ubuntu:~/arm2410s$ mkdir ncurses
lingd@ubuntu:~/arm2410s$ cd ncurses-5.5
lingd@ubuntu:~/arm2410s/ncurses-5.5$ ./configure \
> --prefix=/home/lingd/arm2410s/ncurses \
> --host=arm-linux \
> --target=arm-linux \
> --with-build-cc=cc \
> --with-build-cpp=cpp \
> --with-share \
> --with-normal
然后终端打印大量配置信息,注意最后那几行:说明了ncurses工具、头文件、库文件、帮助文档和终端信息安装在哪个目录下
……
** Configuration summary for NCURSES 5.5 20051010:
extended funcs: yes
xterm terminfo: xterm-new
bin directory: /home/lingd/arm2410s/ncurses/bin
lib directory: /home/lingd/arm2410s/ncurses/lib
include directory: /home/lingd/arm2410s/ncurses/include/ncurses
man directory: /home/lingd/arm2410s/ncurses/man
terminfo directory: /home/lingd/arm2410s/ncurses/share/terminfo
** Include-directory is not in a standard location
3、编译和安装ncurse库
lingd@ubuntu:~/arm2410s/ncurses-5.5$ make
lingd@ubuntu:~/arm2410s/ncurses-5.5$ make install
lingd@ubuntu:~/arm2410s/ncurses-5.5$ cd ../ncurses
lingd@ubuntu:~/arm2410s/ncurses$ ls
bin include lib man share
编译ncurse库时,make install出现如下错误:
./run_tic.sh: line 113: /usr/local/bin/tic: cannot execute binary file
? tic could not build /usr/local/share/terminfo
make[1]: *** [install.data] 错误 1
make[1]: Leaving directory `/opt/ncurses/misc'
make: *** [install] 错误 2
该错误提示:/usr/local/bin/tic不是可执行的二进制文件
file /usr/local/bin/tic发现它是arm平台的,当然无法在pc上运行
[root@localhost ncurses]# file /usr/local/bin/tic
/usr/local/bin/tic: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, statically linked, for GNU/Linux 2.4.3, not stripped
如果pc机上已经安装过ncurses(ncurses是配置内核、根文件系统等需要用到make menuconfig必备的库),那么pc上一定有可以在pc运行的tic。此时,我们find一下tic
[root@localhost ncurses]# find / -name tic
/opt/ncurses/progs/tic
/usr/bin/tic
/usr/local/bin/tic
机子上总共有3个tic,/opt/ncurses/progs/tic是我们刚刚编译的arm版tic,而/usr/local是我们ncurse库的安装点,因此,/usr/local/bin/tic也是arm版tic。最后只剩下/usr/bin/tic就是x86版的tic。我们可以file一下这3个文件,就知道到底是不是这样:
[root@localhost ncurses]# file /usr/bin/tic
/usr/bin/tic: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, statically linked, for GNU/Linux 2.6.9, not stripped
[root@localhost ncurses]# file /usr/local/bin/tic
/usr/local/bin/tic: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, statically linked, for GNU/Linux 2.4.3, not stripped
[root@localhost ncurses]# file /opt/ncurses/progs/tic
/opt/ncurses/progs/tic: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, statically linked, for GNU/Linux 2.4.3, not stripped
接下来,我们看看环境变量PATH
[root@localhost ncurses]# echo $PATH
/opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/dev_home/tools/bin:/root/bin:/root/dev_home/tools/bin:/opt/host/armv4l/bin:/root/dev_home/tools/bin
从PATH内容可以看出,/usr/local/bin在PATH中的位置比/usr/bin前。因此,在搜索tic时,最先找到的是/usr/local/bin/tic,而不是/usr/bin/tic,这才引起了先前的错误。解决方法很简单:只要让先找到的tic是/usr/bin/tic就可以避免该错误!
[root@localhost ncurses]# PATH=/usr/bin:$PATH
这样就ok了,然后重新make install就可以安装上ncurses库
如果pc上没有装x86版ncurses库,Ubuntu系统可以用以下命令安装ncurses库
sudo apt-get install libncurses5-dev
其他Linux系统,可以自己编译x86版ncurses库:
./configure --host=i386-linux --prefix=/usr
make
make install
若为redhat enterprise linux 5将--host=i386-linux改为--host=i686-pc-linux-gnu
4、menu例子程序
menu程序是我写的基于ncurses库的一个例子,源码如下:
先在pc的nfs共享目录(我的是/arm2410s)下,建立terminfo/v目录(我在/arm2410s/basic下建立),用以存放终端信息
[root@localhost basic]# mkdir -p terminfo/v
将ncurses安装目录(我的是/home/lingd/ncurses)下share/terminfo/v/vt102终端信息拷贝到
terminfo/v目录下
[root@localhost basic]# cd terminfo/v
[root@localhost v]# cp /home/lingd/ncurses/share/terminfo/v/vt102 .
[root@localhost v]# ls
vt102开发板上运行menu程序
root@lingd-arm2410s:/# ./shell/mount.sh
root@lingd-arm2410s:/# cd /tmp/basic/ncurses/
root@lingd-arm2410s:/tmp/basic/ncurses# ./menu
Error opening terminal: vt102.
root@lingd-arm2410s:/tmp/basic/ncurses# export TERMINFO=/tmp/basic/terminfo
root@lingd-arm2410s:/tmp/basic/ncurses# ./menu+-------------------my ncurse menu---------------------------------------------+
| |
| |
| |
| |
| |
| [1] option1 |
| |
| [2] option2 |
| |
| [3] option3 |
| |
| [4] option4 |
| |
| [5] exit |
| |
| |
| you select option2! |
| |
| |
| |
| |
| |
+------------------------------------------------------------------------------+注意:
运行基于ncurses库的程序必须先设置终端信息环境变量TERMINFO;否则会提示找不到终端信息。这里我们事先将终端信息vt102拷贝到了/arm2410s/basic/terminfo/v,pc的/arm2410s目录被我挂载到开发板的/tmp目录,所以我的TERMINFO设置为"
export TERMINFO=/tmp/basic/terminfo”。
另外,在运行是ncurses库的程序可能还会提示找不到ncurses的某个库文件,如
root@lingd-arm2410s:/tmp/basic/gprs# ./gprs
./gprs: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
这时,我们先在pc上将arm版ncurses安装目录下的lib,拷贝到共享目录下(
cp /home/lingd/ncurses/lib /arm2410s/basic),然后在开发板上设置一下库文件搜索路径LD_LIBRARY_PATH,再运行程序,一般就没问题了。
root@lingd-arm2410s:/tmp/basic/gprs# export LD_LIBRARY_PATH=${LD_LIBRARY_PATH
}:/tmp/basic/lib
阅读(4594) | 评论(2) | 转发(0) |