借鉴文章网址为
wiki.beyondlogic.org/index.php?title=Cross_Compiling_BlueZ_Bluetooth_tools_for_ARM
编译glib需要zlib libffi两个库文件我使用的库版本为
glib-2.45.3.tar.xz libffi-3.2.1.tar.gz zlib-1.2.8.tar.gz
下载库推荐网址 点击打开链接 http://www.filewatcher.com/
直接输入 zlib-1.2.8.tar.gz 就可以找到所有的ftp下载内容的连接
zlib
./configure --prefix=$(pwd)/install
Edit the makefile and prefix the build tools with arm-linux-gnueabi-.
CC=arm-linux-gnueabi-gcc LDSHARED=arm-linux-gnueabi-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map CPP=arm-linux-gnueabi-gcc -E AR=arm-linux-gnueabi-ar RANLIB=arm-linux-gnueabi-ranlib
Make and install:
make make install
libffi is the Portable Foreign Function Interface Library and is a prerequisite for building GLib. It is an interface that allows code written in one language to call code written in another language.
Download, build and install:
wget ftp://sourceware.org/pub/libffi/libffi-3.0.13.tar.gz tar -xzf libffi-3.0.13.tar.gz cd libffi-3.0.13/ ./configure --host=arm-linux-gnueabi --prefix=/usr/arm-linux-gnueabi make make install
在编译glib的时候最好编译的就是这两个了基本上按照步骤不会出错,我分别在Ubuntu16.04 以及Ubuntu14.04上测试过
下面的这个是推荐网址中给出的原话编译glib的
GLib is part of the GTK+ Project
GLib requires zlib, libffi and glibc >= 2.18 to successfully build. If you are building on ubuntu 14.04, the arm-linux-gnueabi should come installed with glibc 2.19 hence we don't rebuild it.
GLib requires the glib-genmarshal tool installed on your build system otherwise the following error is likey to result:
checking for glib-genmarshal... no configure: error: Could not find a glib-genmarshal in your PATH
An easy way to resolve this is to install libglib2.0-dev:
sudo apt-get install libglib2.0-dev
To build Glib, download, build and install:
wget http://ftp.gnome.org/pub/gnome/sources/glib/2.40/glib-2.40.0.tar.xz tar -xJf glib-2.40.0.tar.xz cd glib-2.40.0 ./configure --host=arm-linux-gnueabi --prefix=/usr/arm-linux-gnueabi PKG_CONFIG_PATH=/usr/arm-linux-gnueabi/lib/pkgconfig glib_cv_stack_grows=no glib_cv_uscore=yes ac_cv_func_posix_getpwuid_r=yes ac_cv_func_posix_getgrgid_r=yes make make install
但是根据上面的操作会导致找不到libffi库在config的时候,并且编译的时候回提示找不到zlib.h头文件
我使用的是一下配置
./configure --prefix=/home/lz/work/hi3536/arm_install --host=arm-hisiv400-linux-gnueabi PKG_CONFIG_PATH=/home/lz/work/hi3536/arm_install LIBFFI_CFLAGS='-I/home/lz/work/hi3536/arm_install/lib/libffi-3.2.1/include' LIBFFI_LIBS='-lffi -L=/home/lz/work/hi3536/arm_install/lib' ZLIB_CFLAGS='-I/home/lz/work/hi3536/zlib-1.2.8/install/include' ZLIB_LIBS='-lz -L/home/lz/work/hi3536/zlib-1.2.8/install/lib' glib_cv_stack_grows=no glib_cv_uscore=yes ac_cv_func_posix_getpwuid_r=yes ac_cv_func_posix_getgrgid_r=yes
--prefix=/home/lz/work/hi3536/arm_install 是我的安装目录可以修改成--prefix=$(pwd)/install 习惯用这个
--host=arm-hisiv400-linux-gnueabi 我的编译器,可以通过增加临时变量例如
export PATH=/opt/hisi-linux-nptl/arm-hisiv400-linux/bin:$PATH
source /etc/profile
使得
arm-hisiv400-linux-gnueabi-gcc 可以正常使用并且不需要手动修改Makefile以及config防止出错编译成gcc版本
PKG_CONFIG_PATH=/home/lz/work/hi3536/arm_install 是我根据这篇文章来设定的目录,我将zlib以及libffi install到这个目录不知道有没有用,贴出来只是给一个参考
LIBFFI_CFLAGS='-I/home/lz/work/hi3536/arm_install/lib/libffi-3.2.1/include'
LIBFFI_LIBS='-lffi -L=/home/lz/work/hi3536/arm_install/lib'
这句是我指定libffi的头文件以及库文件位置
ZLIB_CFLAGS='-I/home/lz/work/hi3536/zlib-1.2.8/install/include'
ZLIB_LIBS='-lz -L/home/lz/work/hi3536/zlib-1.2.8/install/lib'
同样指定zlib的安装目录这个目录是我以前交叉编译安装的目录
glib_cv_stack_grows=no
glib_cv_uscore=yes
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_getgrgid_r=yes
这些是glib的编译选项我理解是的
然后make
make install 就可以成功了