BlueZ的交叉编译

Sam几年前在写Linux下Bluetooth程序时,就基于BlueZ库。3年多过去了,没有再研究过Bluetooth。最近有个需求需要重新研究一下BlueZ中的实现。看看BlueZ,竟然也使用git管理了。再看看结构,变化也非常大。看来重新实现一套BlueZ完整的交叉编译也是有意义的。

 

一.下载blueZ:

www.bluez.org download页面(http://git.kernel.org/?p=bluetooth/bluez.git;a=summary)明确指出git地址为:git://git.kernel.org/pub/scm/bluetooth/bluez.git

 

$sudo git clonegit://git.kernel.org/pub/scm/bluetooth/bluez.git

则将source code下载于本地bluez目录中。

$cd bluez

$./bootstrap  //创建了configure

 

先尝试编译x86版本。

$./configure

$make

顺利编译完成。

 

二:交叉编译BlueZ:

首先查看README,其中明确提到,编译BlueZ utils,需要以下软件包:

In order to compile Bluetooth utilities you need followingsoftware packages:
       - Linux Bluetooth protocol stack(BlueZ)  (这个就是bluez中包含的协议栈部分)
       - GCCcompiler          (编译器)
       - D-Buslibrary           
       - GLib library
       - USB library (optional)
       - Lexical Analyzer (flex, lex)
       - YACC (yacc, bison, byacc)  (yum installbyacc)

 在x86平台,因为这些东西已经安装,他们的库和头文件均可以通过pkg-config查询到。所以没问题。但交叉编译中,则此类库都需要重新交叉编译。

 

让我们从头开始,一步步添加所需要库吧。

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 LIBXML_CFLAGS=-I/home/sam/work/blueZ/3party/expat-2.0.1/libLIBXML_LIBS=-L/home/sam/work/blueZ/3party/expat-2.0.1/.libs ./configure --host=arm-linux --enable-abstract-sockets

$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 是因为configure 需要测试-lexpat以及头文件expat.h是否有.但添加LIBXML_LIBS之后,它并不会在编译临时文件时添加进去。所以只好使用CFLAGS, LDFLAGS。

 

继续编译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  ./configure --host=arm-linux

$make clean;make

此时,不再出现dbus报错和警告。

 

make --no-print-directory all-am
 CC    audio/telephony-dummy.o
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation
 CC    audio/telephony-maemo5.o
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation
 CC    audio/telephony-ofono.o
cc1: warning: include location "/usr/include/glib-2.0" is unsafefor cross-compilation

 

同理,说明要交叉编译glib.

 

2.2: 交叉编译glib.

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 ./configure --host=arm-linux  --disable-audio--enable-alsa=no --enable-pcmcia=no

 

但却又显示:

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/6e5870f7c9c5414572158d8005e91d68/

 

 

 

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 SNDFILE_CFLAGS=-I/home/sam/work/blueZ/3party/libsndfile-1.0.25/srcSNDFILE_LIBS=-L/home/sam/work/blueZ/3party/libsndfile-1.0.25/src/.libs USB_CFLAGS=-I/home/sam/work/blueZ/3party/libusb-1.0.8/libusbUSB_LIBS=-L/home/sam/work/blueZ/3party/libusb-1.0.8/libusb/.libs CFLAGS=-I/home/sam/work/blueZ/3party/check-0.9.3/srcLDFLAGS="-L/home/sam/work/blueZ/3party/check-0.9.3/src-L/home/sam/work/blueZ/3party/glib/glib/.libs-L/home/sam/work/blueZ/3party/dbus-1.4.16/dbus/.libs"LIBS="-lglib-2.0 -ldbus-1" ./configure--host=arm-linux  --enable-alsa=no--enable-gstreamer=no --enable-usb=no

 

$make clean;make

终于编译出来了。但注意,某个文件中用到了ch_access, glib中已经不提供这个符号了。所以Sam自己改掉了。

 

 

 

总结:BlueZ经过这么多年发展,已经依赖于非常多的第三方库,这一方面使其功能更全面,但从嵌入式系统角度来讲,又不是一件好事。因为其依赖的库版本也在不断的提高。但BlueZ不太可能跟踪这些第三方库的最新版本。这就造成了交叉编译的很多困难。例如,下载最新的第三方库,头文件或者符号对不上。但又不清楚应该退到哪个具体老版本。如果第三方库是git管理的。则更加麻烦。因为这些原因,所以blueZ的完整编译越来越让Sam感觉到复杂而不爱尝试。总是草草编译出一部分用到的东西为止。不知道哪位朋友有好的建议。


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值