交叉编译libX11

0 前言    

    本文探索如何将libX11移植到ARM开发板。

1 源码

    从参考资料[1]或这里下载相关源码,本文下载源码为:libX11-1.6.10.tar.gz

 解压源码包:

tar -zxvf  libX11-1.6.10.tar.gz  

2 配置

    创建一个用于目录作为libX11的安装位置(因为是交叉编译,所以不能使用默认的安装目录,否则会破坏ubuntu系统):

mkdir -p third_lib/X11

2.1 环境变量设置

    为了方便配置,可以先设置环境变量(具体值要根据你的目录名和交叉工具链名进行修改):

export PREFIX=/home/wyj/third_lib/X11
export HOST=arm-linux-gnueabihf

    将上述内容保存为env.sh,然后执行以下命令使其生效:

source env.sh

2.2 configure

    进入libX11-1.5.0目录,执行下面命令进行配置

./configure --prefix=$PREFIX --host=$HOST

    配置结果如下:

X11 will be built with the following settings:
 Loadable i18n module support:            no
 Loadable xcursor library support:        yes
 Threading support:                       yes
 Use Threads safe API:                    yes
 Threads stubs in libX11:                 no
 XCMS:                                    yes
 Internationalization support:            yes
 XF86BigFont support:                     no
 XKB support:                             yes
 XLOCALEDIR environment variable support: yes
 Compose table cache enabled:             no
 Functional specs building enabled:       yes

2.2.1  配置错误解决

 在配置libX11-1.6.10时遇到下面错误

     可通过--cache-file参数解决上述错误[:

echo "xorg_cv_malloc0_returns_null=yes" > arm-linux.cache

 ./configure --prefix=$PREFIX --host=$HOST --cache-file=arm-linux.cache

3 编译

    配置好后,就可可以执行以下命令进行编译

make

3.1.  编译错误解决

3.1.1   X11/X.h: No such file or directory

    在移植过程中,遇到各种各样的错误是难免的,关键是找到问题的所在,从而解决它。下面是进行编译时遇到的第一个错误:

make[3]: Entering directory `/home/wyj/third_lib/libX11-1.6.10/modules/im/ximcp'
  CC     imCallbk.lo
In file included from ../../../include/X11/Xlibint.h:41:0,
                 from imCallbk.c:38:
../../../include/X11/Xlib.h:44:19: fatal error: X11/X.h: No such file or directory
compilation terminated.
make[3]: *** [imCallbk.lo] Error 1


    下载xproto-7.0.31.tar.gz(可到这里下载更新版本),然后将其加压到上面创建的third_lib目录中,进入xproto-7.0.31目录,执行以下命令来配置和安装xproto。

./configure --prefix=$PREFIX --host=$HOST
make
make install


    这时,上面创建的X11目录中就多了一些目录(inclue、lib、share)和其它相关文件,其中include/X11目录包含了X.h文件。

    然而,就算有了X.h头文件,在编译过程中编译工具也不会自动找到它。其实,使用find命令可以找到ubuntu的/usr/include/X11中是存在X.h这头文件的。现在是交叉编译,交叉编译工具不会自动的到/usr/include目录中去寻找头文件,当然也不会到X11/include这个用户自己创建的目录去找,除非用户指定。

    然而,由于Makefile的内容太多,而且非常复杂,直接修改其中的includedir变量时,发现无济于事。这时,唯一的办法就是指定PKG_CONFIG_PATH环境变量(原因请看《pkg-config》)。

    将2.1中的环境变量添加“export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig”:

export PREFIX=/home/wyj/third_lib/X11
export HOST=arm-linux-gnueabihf
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig  # 新增

   然后再次source env.sh使其生效,然后按照2.2小节的方法重新配置X11,然后再次编译即可。

3.1.2 X11/Xtrans/Xtrans.h: No such file or directory

    下载xtrans-1.4.0.tar.gz(可到这里下载最新版本),解压到third_lib目录中,然后使用3.1.1同样的方法配置和安装xtrans。

    然后,继续编译libX11即可解决此问题。

3.1.3 X11/extensions/XKBproto.h: No such file or directory

    下载kbproto-1.0.7.tar.gz(可点击这里下载最新版本),解压到third_lib目录中,然后使用3.1同样的方法配置和安装xbproto。

    然后,继续编译libX11即可解决此问题。

3.1.4 X11/extensions/XI.h: No such file or directory

    下载inputproto-2.3.2.tar.gz,(可点击这里下载最新版本),解压到third_lib目录中,然后使用3.1.1同样的方法安配置和安装inputproto。

    然后,继续编译libX11即可解决此问题。

3.1.5 xcb/xcb.h: No such file or directory

    下载libxcb-1.14.tar.xz(可到这里下载更新版本),解压到third_lib目录中,然后使用3.1.1同样的方法配置和安装libxcb。在配置libxcb的过程中,会出现以下错误

 (1)configure: error: XCB requires xsltproc.

    那是因为ubuntu中没有xsltproc这个工具导致的可以使用下面命令安装一个:

sudo apt-get install xsltproc

(2)No package 'xcb-proto' found

    Ubuntu PC需要安装:

sudo apt-get install xcb-proto

    此外,需要交叉编译:

    下载xcb-proto-1.14.1.tar.gz(可到这里下载更新版本),解压到third_lib目录中,然后使用3.1.1同样的方法配置和安装xcb-proto。

 (3)X11/Xauth.h: No such file or directory

     下载libXau-1.0.9.tar.gz,然后使用3.1.1同样的方法配置和安装libXau。

(4)cannot find -lXau

    由于已经完成了libXau的安装,因此libXau.so库已经存在X11/lib目录中。这时编译器却找不到它。因此需要指定库的路径。在env.sh中添加LD_LIBRARY_PATH设置,如下所示:

export PREFIX=/home/liyihai/downloads/libX11_install
export HOST=arm-arago-linux-gnueabi
export LD_LIBRARY_PATH=$PREFIX/lib
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig

    执行source env.sh命令使其生效。

    继续编译libxcb,这时没有新的错误。编译成功后make install安装即可。

3.1.6 X11/extensions/xf86bigfproto.h: No such file or directory

     下载xorgproto-2020.1.tar.bz2(可到这里下载更新版本),解压,然后使用3.1.1同样的方法配置和安装即可。

wget https://xorg.freedesktop.org/archive/individual/proto/xorgproto-2020.1.tar.bz2

3.1.7  x11/extensions/XShm.h: No such file or directory

  下载libXext-1.3.4.tar.gz(可到这里下载更新版本),解压,然后使用3.1.1同样的方法配置和安装即可。

3.1.8  X11/xshmfence.h: No such file or directory


     下载libxshmfence_1.3.orig.tar.gz,(新版本)解压,然后使用3.1.1同样的方法配置和安装即可。

4 安装

     安装libX11是最省事的,直接执行以下命令即可。

 make install


 

Supongo que te gusta

Origin blog.csdn.net/ggggyj/article/details/120300854
Recomendado
Clasificación