Sam几年前在写Linux下Bluetooth程序时,就基于BlueZ库。3年多过去了,没有再研究过Bluetooth。最近有个需求需要重新研究一下BlueZ中的实现。看看BlueZ,竟然也使用git管理了。再看看结构,变化也非常大。看来重新实现一套BlueZ完整的交叉编译也是有意义的。
一.下载blueZ:
www.bluez.org
$sudo git clonegit://git.kernel.org/pub/scm/bluetooth/bluez.git
则将source code下载于本地bluez目录中。
$cd bluez
$./bootstrap
先尝试编译x86版本。
$./configure
$make
顺利编译完成。
二:交叉编译BlueZ:
首先查看README,其中明确提到,编译BlueZ utils,需要以下软件包:
In order to compile Bluetooth utilities you need followingsoftware packages:
让我们从头开始,一步步添加所需要库吧。
2.0: 尝试编译bluez--1
#CC=arm-hisiv200-linux-gnueabi-gcc ./configure--host=arm-linux
#make
出现错误如下:
cc1: warning: include location "/usr/include/dbus-1.0" is unsafefor cross-compilation
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation
非常明显,编译器也察觉到dbus 不是对应平台版本。所以提出警告。则我们首先交叉编译dbus.
2.1 交叉编译d-bus.
2.1.1:下载d-bus source code
http://www.freedesktop.org/wiki/Software/dbus#Download
$CC=arm-hisiv200-linux-gnueabi-gcc ./configure--host=arm-linux
显示error 如下:
checking for XML_ParserCreate_MM in -lexpat... no
configure: error: Could not find expat.h, check config.log forfailed attempts
少xml解析的expat.
2.1.2: 下载expat.
http://sourceforge.net/projects/expat/
$cd expat-2.0.1
$CC=arm-hisiv200-linux-gnueabi-gcc ./configure--host=arm-linux
$make clean;make
正常编译出expat.
2.1.3: 编译D-bus.
$CC=arm-hisiv200-linux-gnueabi-gccCFLAGS=-I/home/sam/work/blueZ/3party/expat-2.0.1/libLDFLAGS=-L/home/sam/work/blueZ/3party/expat-2.0.1/.libs
$make clean;make
其中CFLAGS=-I/home/sam/work/blueZ/3party/expat-2.0.1/libLDFLAGS=-L/home/sam/work/blueZ/3party/expat-2.0.1/.libs
继续编译bluez--2:
$CC=arm-hisiv200-linux-gnueabi-gccDBUS_CFLAGS=-I/home/sam/work/blueZ/3party/dbus-1.4.16DBUS_LIBS=-L/home/sam/work/blueZ/3party/dbus-1.4.16/dbus/.libs
$make clean;make
此时,不再出现dbus报错和警告。
make --no-print-directory all-am
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation
同理,说明要交叉编译glib.
2.2:
glib是GUN项目的一部分,www.gnu.org中点选glib可以找到下载位置:
$git clone git://git.gnome.org/glib
$cd glib
$./autogen.sh
which: no gtkdocize in(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/sam/bin:/opt/hisi-linux/x86-arm/arm-hisiv200-linux/bin/)
*** No GTK-Doc found, please install it ***
少GTK-Doc
则安装之:
$ sudo yum install gtk-doc
又报少
configure: error: Package requirements (libffi >=3.0.0) were not met:
No package 'libffi' found
$sudo yum install libffi
$sudo yum install libffi-devel
之后再次运行./autogen.sh
则顺利生成configure.
运行./configure
此时会出现一个经典问题,即configure 程序会报:交叉编译处的结果不能在host上运行。呵呵,想想当然是这样了。
很好解决,把configure中需要判断的AC项找出来,在configure中设置就好。
$CC=arm-hisiv200-linux-gnueabi-gcc ./configure--host=arm-linux glib_cv_stack_grows=noglib_cv_uscore=yes
ac_cv_func_posix_getpwuid_r=yesac_cv_func_posix_getgrgid_r=yesglib_cv_have_qsort_r=yes
#make clean;make
再次编译bluez--3
CC=arm-hisiv200-linux-gnueabi-gccDBUS_CFLAGS=-I/home/sam/work/blueZ/3party/dbus-1.4.16DBUS_LIBS=-L/home/sam/work/blueZ/3party/dbus-1.4.16/dbus/.libsGLIB_CFLAGS="-I/home/sam/work/blueZ/3party/glib/-I/home/sam/work/blueZ/3party/glib/glib"GLIB_LIBS=/home/sam/work/blueZ/3party/glib/glib/.libs
但却又显示:
sbc/sbctester.c:32: fatal error: sndfile.h: No such file ordirectory
2.3: 下载编译libsndfile,check-0.9.3.tar.gz
于是下载libsndfile.
http://www.mega-nerd.com/libsndfile/#Download
$CC=arm-hisiv200-linux-gnueabi-gcc ./configure--host=arm-linux
$make clean;make
虽然sndfilehandle编译失败,但其它用到的都OK了。
check:
http://pkgs.fedoraproject.org/repo/pkgs/check/check-0.9.3.tar.gz/6e5870f7c9c5414572158d80
blueZ最后的编译:
CC=arm-hisiv200-linux-gnueabi-gccDBUS_CFLAGS=-I/home/sam/work/blueZ/3party/dbus-1.4.16DBUS_LIBS=-L/home/sam/work/blueZ/3party/dbus-1.4.16/dbus/.libsGLIB_CFLAGS="-I/home/sam/work/blueZ/3party/glib/-I/home/sam/work/blueZ/3party/glib/glib"GLIB_LIBS=-L/home/sam/work/blueZ/3party/glib/glib/.libs
$make clean;make
终于编译出来了。但注意,某个文件中用到了ch_access, glib中已经不提供这个符号了。所以Sam自己改掉了。
总结:BlueZ经过这么多年发展,已经依赖于非常多的第三方库,这一方面使其功能更全面,但从嵌入式系统角度来讲,又不是一件好事。因为其依赖的库版本也在不断的提高。但BlueZ不太可能跟踪这些第三方库的最新版本。这就造成了交叉编译的很多困难。例如,下载最新的第三方库,头文件或者符号对不上。但又不清楚应该退到哪个具体老版本。如果第三方库是git管理的。则更加麻烦。因为这些原因,所以blueZ的完整编译越来越让Sam感觉到复杂而不爱尝试。总是草草编译出一部分用到的东西为止。不知道哪位朋友有好的建议。
本文详细记录了BlueZ在嵌入式系统上的交叉编译过程,包括所需第三方库如D-Bus、glib及libsndfile等的编译配置,并解决了交叉编译中遇到的各种问题。

2178

被折叠的 条评论
为什么被折叠?



