移植 libxml2-2.9.4 到arm

2019-07-13 05:53发布

一、环境介绍

1.1 宿主机

Ubuntu 1404 32 位

1.2 嵌入式平台

ATMEL AT91SAM9X25

1.3 交叉工具链

arm-none-linux-gnueabi libxml2-2.9.4移植所需源码包下载地址

二、交叉编译

2.1 先编译 libxml2-2.9.4 依赖的模块

2.1.1 libicobv

tar xvf libiconv-1.15.tar.gz cd libiconv-1.15/ ./configure --prefix=$PWD/tmp --host=arm-none-linux-gnueabi --build=i686-linux make V=s make install

2.1.2 zlib

tar xvf zlib-1.2.11.tar.xz cd zlib-1.2.11/ export CC=arm-none-linux-gnueabi-gcc ./configure --prefix=$PWD/tmp make CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar LD=arm-none-linux-gnueabi-ld ANLIB=arm-none-linux-gnueabi-ranlib make install

2.1.3 xz

tar xvf xz-5.2.0.tar.gz cd xz-5.2.0/ ./configure --prefix=$PWD/tmp --host=arm-none-linux-gnueabi --build=i686-linux make make install

2.1.4 python

tar xvf Python-2.7.13.tgz cd Python-2.7.13/ ./configure make python Parser/pgen mv python hostpython mv Parser/pgen Parser/hostpgen make distclean patch -p1 < ../Python-2.7.13-xcompile.patch ./configure --host=arm-none-linux-gnueabi --prefix=$PWD/tmp --build=i686-linux --enable-ipv6 --enable-shared ac_cv_file__dev_ptmx="yes" ac_cv_file__dev_ptc="no" make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPLIE=arm-none-linux-gnueabi- CROSS_COMPLIE_TARGET=yes HOSTARCH=arm-none-linux-gnueabi BUILDARCH=i686-linux-gnu -j2 make install 在 make install 之前需对 Makefile 做如下修改
删除 Makefile 1141 ~ 1162 1141 PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) 1142 $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py 1143 -d $(LIBDEST) -f 1144 -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' 1145 $(DESTDIR)$(LIBDEST) 1146 PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) 1147 $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py 1148 -d $(LIBDEST) -f 1149 -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' 1150 $(DESTDIR)$(LIBDEST) 1151 -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) 1152 $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py 1153 -d $(LIBDEST)/site-packages -f 1154 -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages 1155 -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) 1156 $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py 1157 -d $(LIBDEST)/site-packages -f 1158 -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages 1159 -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) 1160 $(HOSTPYTHON) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt 1161 -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) 1162 $(HOSTPYTHON) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt

2.2 编译 libxml2

tar xvf libxml2-2.9.4.tar.gz cd libxml2-2.9.4/ ./configure --prefix=$PWD/tmp --host=arm-none-linux-gnueabi --build=i686-linux CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar LD=arm-none-linux-gnueabi-ld ANLIB=arm-none-linux-gnueabi-ranlib --with-zlib=/home/gino/work/jiaxian/9X25/transplant/xml_note/zlib-1.2.11/tmp --with-iconv=/home/gino/work/jiaxian/9X25/transplant/xml_note/libiconv-1.15/tmp --with-lzma=/home/gino/work/jiaxian/9X25/transplant/xml_note/xz-5.2.0/tmp --with-python=/home/gino/work/jiaxian/9X25/transplant/xml_note/Python-2.7.13/tmp make make install

三、使用测试

3.1 测试源码

3.1.1 PC 测试

安装库 sudo apt-get install libxml2-dev libxml2 libxml2-doc 编译 gcc -I/usr/include/libxml2 test_libxml2_2.c -lxml2

3.1.2 ATMEL 9X25 测试

安装库
  1. 将编译所需的头文件和库文件拷贝到工具链所在目录
cp -rv include/* /opt/arm-2010q1/arm-none-linux-gnueabi/libc/usr/include cp -rv lib/* /opt/arm-2010q1/arm-none-linux-gnueabi/libc/usr/lib/
  1. 如果程序连接使用的是动态库,需将动态库拷贝到运行环境。
编译 arm-none-linux-gnueabi-gcc -I /opt/arm-2010q1/arm-none-linux-gnueabi/libc/usr/include/libxml2/ test_libxml2_2.c -o arm-libxml -lxml2

四、补充

源码文件运行会出现乱码,是源码程序编码问题,与本记录无关,暂不关注。