【转】ARM下面移植开发BlueZ

 

下面是直接从网上转过来的:

 



 

前一段的时间,都在移植BlueZ的库文件和工具基到ARM的开发板,现在的整个一套设备已经基本完成。内核是开发板自己带的 2.6.13,从2.4.6后的版本里就已经在内核里带有了BlueZ支持,我要做的就是,进入Networking子项,build-in 上Bluetooth subsystem support。下面的L2CAP protocol support和SCO links support选中, Bluetooth device drivers里的是关于你使用USB蓝牙还是串口蓝牙,根据你的需要选择。 HCI VHCI (Virtual HCI device) driver是一个虚拟HCI接口,可以使你在没有蓝牙设备的使用,测试你的蓝牙应用程序,没有使用过。 保存退出,make。编译出新的内核镜像文件。

   现在开始移植bluez的库文件和工具集。使用的版本是 bluez-lib-3.36和bluez-utils-3.36arm-linux-gcc的版本为3.3.2 内核版本为kernel-2.6.13 编译内核和根文件系统要使用相同版本的交叉编译工具,否则编译出来的命令不能执行,出现段错误。

   configure时的一点建议,configure脚本指定make install的安装目录,--prefix= 可以配置,个人感觉还是不使用这个选项。这样一般会安装到/usr下,(具体看源代码的INSTALL文件),所以编译完成后一定不能make isntall!否则会覆盖宿主系统的软件。这样做的好处是使你的目标系统目录结构很清晰,比如/usr/bin下存放的都是用户的可执行文件。/etc下都是各个软件的配置文件目录。软件的临时文件都存放在/tmp下,log信息/var下。因此我只make编译出可执行文件或库文件,然后手工拷贝到目标板中响应目录下。但这样做的前提是你要知道需要拷贝那些文件以及他们的位置。一个是通过INSTALL文件。另一个笨方法是编译两次,第一次指定--prefix=,编译并安装,查看都需要那些文件以及他们的位置,第二次不使用--prefix=只编译不安装,并参考第一次手动拷贝。

   两次编译还有一个好处是当这个源代码包被其他的源码包所依赖时,可以使用生成的.pc文件替换宿主系统的.pc文件,为其他包的编译带来便利。具体原理和用方法请参考pkg-config的用法。http://linux.chinaunix.net/bbs/archiver/tid-1058530.html

   当然也可以使用configure的其他选项来自定义你的目录结构,--bindir & --exec-prefix=PREFIX等。具体的参考--help帮助。

现在将编译中遇到的错误贴出来:

1. 编译bluez-libs-3.36

[mystic@moolenaar]$ ./configure --host=arm-linux  CC=arm-linux-gcc 

make编译通过。把make后生成的bluez.pc文件拷贝到/usr/lib/pkgconfig目录但要做好pc版本的bluez.pc的备份。下以便交叉编译完bluez后恢复。这个bluez.pc要使用

copy bluez.pc to usr/lib/pkgconfig

 

2. 编译bluez-utils-3.36,缺少D-Bus

[mystic@moolenaar]$ ./configure --host=arm-linux  

 

checking pkg-config is at least version 0.9.0... yes

checking for BLUEZ... yes

checking for GLIB... no

checking for GMODULE... no

checking for dlopen in -ldl... yes

checking for DBUS... no

configure: error: D-Bus library is required

 

bluez-utils需要d-bus包的支持,下载d-bus的源代码编译安装。bluez-utils需要的其他一些源码包将在最后贴出。(包括使用的版本号)

 

3. 编译D-Bus,can not run test program while cross compiling

[mystic@moolenaar]$ ./configure --host=arm-linux --prefix=/bluez/dbus  CC=arm-linux-gcc

checking for getpeereid... no

checking abstract socket namespace... configure: error: cannot run test program while cross compiling

See `config.log' for more details.

执行./configure时要在宿主系统中运行一些测试程序,因为是交叉编译所以这个测试是一定通不过的。不过没问题,我们可以在configure时指定cache-file文件来屏障掉测试程序,在下面编译glib包时会遇到同样的问题。

 

处理方法:

在源码包根目录下执行

[mystic@moolenaar]$ echo ac_cv_have_abstract_sockets=yes > arm-linux.cache

[mystic@moolenaar]$ ./configure --host=arm-linux --prefix=/bluez/dbus  CC=arm-linux-gcc --cache-file=arm-linux.cache

 

./configure通过后,执行make,出现如下错误:

make[2]: *** [config-loader-libxml.o] error 1

make[2]: Leaving directory `/3.3.2/dbus-1.0.2/bus'

make[1]: *** [all-recursive] error 1

make[1]: Leaving directory `/3.3.2/dbus-1.0.2'

make: *** [all] error 2

缺少xml库,下载编译安装后,copy  libxml-2.0.pc /usr/lib/pkgconfig 就可以了。

 

4. 编译dbus,cannot find -lX11

[mystic@moolenaar]$ make

arm-linux/bin/ld: cannot find -lX11

collect2: ld returned 1 exit status

make[2]: *** [dbus-launch] error 1

make[2]: Leaving directory `/3.3.2/dbus-1.0.2/tools'

make[1]: *** [all-recursive] error 1

make[1]: Leaving directory `/3.3.2/dbus-1.0.2'

make: *** [all] error 2

在开发板上不需要X Server. configure直接屏蔽掉。

 

[mystic@moolenaar]$ ./configure --host=arm-linux --prefix=/bluez/dbus  CC=arm-linux-gcc --cache-file=arm-linux.cache --without-x

 
5. 编译bluez-utils, 缺少宏定义

bridge.c:82: error: `SIOCBRADDBR' undeclared (first use in this function)

bridge.c:82: error: (Each undeclared identifier is reported only once

bridge.c:82: error: for each function it appears in.)

bridge.c: In function `bridge_remove':

bridge.c:100: error: `SIOCBRDELBR' undeclared (first use in this function)

bridge.c: In function `bridge_add_interface':

bridge.c:126: error: `SIOCBRADDIF' undeclared (first use in this function)

make[2]: *** [bridge.lo] error 1

make[2]: Leaving directory `/3.3.2/bluez-utils-3.36/network'

make[1]: *** [all-recursive] error 1

make[1]: Leaving directory `/3.3.2/bluez-utils-3.36'

make: *** [all] error 2

 

bluez-utils-3.36/network/bridge.h中添加如下宏定义:

#define SIOCBRADDBR     0x89a0          /* create new bridge device     */

#define SIOCBRDELBR     0x89a1          /* remove bridge device         */

#define SIOCBRADDIF     0x89a2          /* add interface to bridge      */

#define SIOCBRDELIF     0x89a3          /* remove interface from bridge */

 

6. 编译bluez-utils

[mystic@moolenaar]$ make

storage.c  -fPIC -DPIC -o .libs/storage.o

storage.c: In function `encrypt_link':

storage.c:286: error: `ENOKEY' undeclared (first use in this function)

storage.c:286: error: (Each undeclared identifier is reported only once

storage.c:286: error: for each function it appears in.)

make[2]: *** [storage.lo] error 1

make[2]: Leaving directory `/3.3.2/bluez-utils-3.36/input'

make[1]: *** [all-recursive] error 1

make[1]: Leaving directory `/3.3.2/bluez-utils-3.36'

make: *** [all] error 2

 

在bluez-utils-3.36/input/storage.c加入宏定义

#define ENOKEY EACCES

 

还会遇到缺少audio模块的错误,我的蓝牙中没有使用audio,所以在./configure时也直接--disable-audio。

 



 

下面是从另外一位网友的博客上转的,感觉比较好,但是出现的错误没有解决,但是在上面的内容中解决了!

 



注:/opt/libs 和/opt/utils是我自己编译时用的路径,你可以随便的选取。

1,编译安装bluez-lib-3.36.tar.gz

   这个库不需要什么依赖,直接解压,配置,编译然后安装即可。

  #tar zxvf bluez-lib-3.36.tar.gz

  #./configure --prefix=/opt/libs --host=arm-linux --target=arm-linux CC=arm-linux-gcc

  #make 

  #make install


2,编译安装

  这个库是后面的dbus依赖的,你也可以用expat来代替libxml2,官方网站上说dbus必须依赖于他们中的一个。

  #tar zxvf libxml2-2.7.4.tar.gz

  #./configure --prefix=/opt/libs --host=arm-linux --target=arm-linux     CC=arm-linux-gcc

  #make 

  #make install


3,编译安装dbus-1.0.2.tar.gz

  #tar zxvf dbus-1.2.16.tar.gz

  #echo ac_cv_have_abstract_sockets=yes>arm-linux.cache

  #./configure --prefix=/opt/libs --host=arm-linux --target=arm-linux     CC="arm-linux-gcc -I/opt/libs/include -L/opt/libs/lib" --cache-file=arm-linux.cache --with-x=no

  #make 

  #make install


4,编译安装glib-2.16.5

  #tar  -zxjf  glib-2.16.5.tar.bz2

#echo ac_cv_type_long_long=yes>arm-linux.cache

#echo glib_cv_stack_grows=no>>arm-linux.cache

#echo glib_cv_uscore=no>>arm-linux.cache

#echo ac_cv_func_posix_getpwuid_r=yes>>arm-linux.cache

#echo ac_cv_func_posix_getgrgid_r=yes>>

注意:">"和">>"的区别

#./configure --prefix=/opt/libs --host=arm-linux --target=arm-linux     CC="arm-linux-gcc -I/opt/libs/include -L/opt/libs/lib" --cache-file=arm-linux.cache

#make 

#make install


5,编译安装libusb-0.1.12.tar.gz

   这个库不需要什么依赖,直接解压,配置,编译然后安装即可。

  #tar zxvf  libusb-0.1.12.tar.gz

  #./configure --prefix=/opt/libs --host=arm-linux --target=arm-linux CC="arm-linux-gcc -I/opt/libs/include -L/opt/libs/lib"

  #make 

  #make install


6,编译安装bluez-utils-3.36.tar.gz

  #tar zxvf bluez-utils-3.36.tar.gz

  #./configure --prefix=/opt/libs --host=arm-linux --target=arm-linux     CC="arm-linux-gcc -I/opt/libs/include -L/opt/libs/lib" --disable-audio

  #make 

  #make install

这样Bluez协议栈就编译好了。


三,烧写到开发板上

     实际上放到板上的只需要

 

 

l2cap.o                 libbluetooth.so.2.11.2          
start.sh                libbluetooth.so                                
bnep.o                  libbluetooth.so.2                            
hci_usb.o                      
rfcomm.o

start.sh是启动模块的支持,也可以insmod进去,其他的是程序要用到的库。

 



可能遇到的错误及解决方法:
a、编译程序的时候
wen@wen-desktop:~$ arm-linux-gcc -I/home/wen/bluez/bluez-libs-3.36_install/include  -L/home/wen/bluez/bluez-4.69/lib/.libs client.c -o client_arm/tmp/ccGbPHFl.o(.text+0x38): In function `main':
: undefined reference to `hci_get_route'
/tmp/ccGbPHFl.o(.text+0x48): In function `main':
: undefined reference to `hci_open_dev'
/tmp/ccGbPHFl.o(.text+0xd4): In function `main':
: undefined reference to `str2ba'
collect2: ld returned 1 exit status
wen@wen-desktop:~$ arm-linux-gcc -I/home/wen/bluez/bluez-libs-3.36_install/include  -L/home/wen/bluez/bluez-4.69/lib/.libs -lbluetooth client.c -o client_arm
wen@wen-desktop:~$

-lbluetooth 就是代表-llibbluetooth.so -L <包含库的目录> -lbluetooth

就是找此目录下的libbluetooth.so或者libbluetooth.a去链接


b、libgmodule.so :invalid reconize
libgmodule.so在glib里面,再在配置文件中改为CC="arm-linux-gcc -L/glib_lib_dir"

c、storage.c:286: error: `ENOKEY' undeclared (first use in this function)
在 bluez-utils-3.36/input/storage.c 中添加宏定义:#define ENOKEY 161 

d、__libc_csu_init undefined reference to `__init_array_end'
配置文件里面的编译器加-shared为:CC="arm-linux-gcc -shared 。。。"

e、cc1: error: unrecognized command line option "-fvisibility=hidden
说是编译器版本太低的缘故。在高版本里面才支持"-Wno-pointer-sign"、"-fvisibility=hidden"。
后来使用PC上的编译器(gcc版本4.4.1,而arm-linux-gcc是3.4.4)试了一下,就没出现这个错误,由此可推断确实是编译器版本问题。既然低版本没有这个指令,我就删掉libusb-compat-0.1.3/libusb/Makefile里面的"-Wno-pointer- sign"和"-fvisibility=hidden",之后OK(如果其他Makefile也有,也要删)。编完之后也要将库和头文件复制到工具链里面去。

f、configure: error: Netlink library is required

解决方法: apt-get install libnl-dev     and     libnl-doc


h、 解决安装glib的编译错误
 stack pointer 问题:
echo ac_cv_type_long_long=yes>arm-linux.cache
echo glib_cv_stack_grows=no>>arm-linux.cache
echo glib_cv_uscore=no>>arm-linux.cache
echo ac_cv_func_posix_getpwuid_r=yes>>arm-linux.cache

i、configure: error: Could not find a glib-genmarshal in your PATH
网上:解压glib2-devel-2.4.7-1.tar.gz, 将文件复制到/usr/local下面
实际:$ sudo apt-get install libglib2.0-dev
原来下载个这东西就行了

j、checking for growing stack pointer... configure: error: cannot run test program while cross compiling
#echo ac_cv_type_long_long=yes>arm-linux.cache

#echo glib_cv_stack_grows=no>>arm-linux.cache

#echo glib_cv_uscore=no>>arm-linux.cache

#echo c_cv_func_posix_getpwuid_r=yes>>arm-linux.cache


k、checking for posix getpwuid_r... configure: error: in `/home/yan/glib-2.22.4':

configure: error: cannot run test program while cross compiling

See `config.log' for more details.


解决方法:ppcst# echo ac_cv_func_posix_getwuid_r=yes


l、源代码安装glib-2.22.5

root@zhupan-desktop:/home/zhupan/glib-2.22.5# ./configure

configure: error:

*** You must have either have gettext support in your C library, or use the

*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html

解决:

i. 尝试 apt-get install gettex,错误,提示:E: 无法找到软件gettext
ii. 下载gettext-0.16.1安装

m、
configure: error: Netlink library is required
configure: error: dbus library is required

1、wen@wen-desktop:~/bluez/bluez-4.69$ export DBUS_CFLAGS=/home/wen/bluez/libxml/include    /libxml2/libxml
wen@wen-desktop:~/bluez/bluez-4.69$ export DBUS_LIBS=/home/wen/bluez/libxml/lib
2、把编译出来的两个lib的pkconfig里面的.pc放到/usr/lib/pkgconfig/里面,或者设置在PKG_CONFIG_PATH里面

n、. 编译D-Bus,can not run test program while cross compiling

[mystic@moolenaar]$ ./configure --host=arm-linux --prefix=/bluez/dbus  CC=arm-linux-gcc

checking for getpeereid... no

checking abstract socket namespace... configure: error: cannot run test program while cross compiling

See `config.log' for more details.

执行./configure时要在宿主系统中运行一些测试程序,因为是交叉编译所以这个测试是一定通不过的。不过没问题,我们可以在configure时指定cache-file文件来屏障掉测试程序,在下面编译glib包时会遇到同样的问题。

处理方法:
在源码包根目录下执行
[mystic@moolenaar]$ echo ac_cv_have_abstract_sockets=yes > arm-linux.cache
[mystic@moolenaar]$ ./configure --host=arm-linux --prefix=/bluez/dbus  CC=arm-linux-gcc --cache-file=arm-linux.cache


o./configure出现
checking for C compiler default output file name... configure: error: C compile cannot execulable
查看:config.log文件,发现是环境变量(LIBS  LDFLAGS)设置错误,和lib


p、configure: error: libxml library is required


缺少xml库,下载编译安装后,copy  libxml-2.0.pc /usr/lib/pkgconfig 就可以了。


q、/bin/rm: cannot remove `libtoolT': No such file or directory
Done configuring
libxml的配置出现以上问题;
解决:可以直接编译make,不影响


r、/tmp/ccs2uTxL.o(.text+0x38): In function `main':
: undefined reference to `hci_get_route'
/tmp/ccs2uTxL.o(.text+0x48): In function `main':
: undefined reference to `hci_open_dev'
/tmp/ccs2uTxL.o(.text+0xd4): In function `main':
: undefined reference to `str2ba'
collect2: ld returned 1 exit status
解决方法:
-lbluetooth

s、
client.c:3:22: bluetooth.h: No such file or directory
client.c:4:16: hci.h: No such file or directory
client.c:5:20: hci_lib.h: No such file or directory
client.c:6:19: rfcomm.h: No such file or directory


解决方法:
-I/头文件目录

t、[转]error: cannot run test program while cross compili
在交叉编译的时候总是使用configure --host=arm-linux 嘿嘿但是在CONFIGURE中有很多的
测试程序是不可以在HOST上运行的就会出现: error: cannot run test program while cross compiling
注意到abstract socket namespace在configure中查找abstract socket可以看到类似这样>的结构
echo "$as_me:$LINENO: checking abstract socket namespace" >&5
echo $ECHO_N "checking abstract socket namespace... $ECHO_C" >&6
if test "${ac_cv_have_abstract_sockets+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
其中ac_cv_have_abstract_sockets是我们要查找的变量
使用echo ac_cv_have_abstract_sockets=yes>arm-linux.cache
然后
./configure --host=arm-linux --cache-file=arm-linux.cache
OK这样就搞定了

u、问题:arm_linux -randlgcc cannoe found
解决办法:到root权限下make  并检查arm-linux-gcc 有没有加到PATH中

v、configure: error: GLib library version 2.14 or later is required
1 设置环境变量GLIB与LIBS, ./configure --help里面查看;
2 把编出来的库lib/pkconfig/*.pc放到/usr/lib/pkgconfig

pkconfig的使用看前两篇文章;

 

 



 

 

bluez-utils-3.36依赖的其他源码包:

[glib必须使用2.14以后版本。编译utils包时,g_timeout_add_seconds函数在此版本以后定义]

 

dbus-1.0.2

glib-2.14.4

libxml2-2.6.11

libsndfile-1.0.17

libusb-0.1.12

 



 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值