Chinaunix首页 | 论坛 | 博客
  • 博客访问: 689613
  • 博文数量: 66
  • 博客积分: 2418
  • 博客等级: 大尉
  • 技术积分: 1659
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-28 10:04
个人简介

keep moving

文章分类

全部博文(66)

文章存档

2015年(2)

2014年(6)

2013年(7)

2011年(7)

2010年(42)

2009年(2)

分类: 嵌入式

2010-05-17 20:18:24

操作系统:      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
阅读(4173) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

songjyf2013-11-07 13:56:08

之后有arm-linux-gcc -o hello hello.c -lncurses 来进行编译,但是提示.
 error: curses.h: No such file or directory
于是我在源程序用绝对路径,/usr/local/arm/arm-2008q1/include/ncurses/
编译时出现很多错误,是指curses.h的.比如:
urses.h: In function 'NCURSES_EXPORT_VAR':
curses.h:250: error: expected declaration specifiers before 'acs_map'
curses.h:340: error: storage class specified for parameter 'SCREEN'
curses.h:341: error: storage class specifi

songjyf2013-11-07 13:56:01

我用的ncurses5.9,编译安装都正常,但是我使用时却出现问题,
我写了一个测试车给你需hello如下:
#define LEFTEDGE  10
#define RIGHTEDGE  30
#define ROW  10


int main(void)
{
  int i;
  char message[6] = "hello";
  char blank[6] = "     ";
  int dir = 1;
  int pos = LEFTEDGE;

  initscr();
  clear();
  while (1