BLUEZ在Linux下的移植

來源:互聯網
上載者:User

下bluez的移植~

    bluez的移植可以用兩個字概括:麻煩!原因是它不是單純的bluez的編譯,它還需要其他很多的庫的支援,下面先列舉一下這些庫的麻煩依賴關係吧:
  bluez-libs-3.36(不需要其他庫)

bluez-utils-3.36:glib-2.16.5
dbus-1.0.2:libxml2-2.7.4
libsndfile-1.0.17
libusb-0.1.12
    前面兩個必須的,後兩個看你的配置,bluez4也一樣;

下面開始編譯:

       Bluez移植到arm s3c2410上

 

 

   搞了好幾天的藍芽協議棧(bluez)的移植,現在終於有點小成就了,寫下來和大家分享。以下介紹Bluez移植的基本步驟。

   一,linux核心的配置

        Linux 2.6版本之後的核心一般都有藍芽模組的配置,所以你不用再打補丁了。由於我也是處於摸索階段,所以我暫時用的是開發板上內建的核心。

    #tar  zxvf   linux.2.6.*

   解壓縮核心,進入核心目錄。在名令行輸入

# make disclean/make clean/make rmproper,

選擇這三個中的任意一個 對核心進行清理,關於這三個命令的區別你可以google一下,然後自己去區分。

#make menuconfig/make config /make oldconfig /make xconfig

輸入如這三個命令中的任何一個,對核心進配置,這幾條命令的區別,請你自己google。推薦使用make menuconfig 。進入核心配置介面之後,根據你的自己的需要進行選擇。關於核心的配置請單獨查看核心配置方面的文檔。

#make zImage ARCH=arm CROSS_COMPILE=arm-linux-

到此核心鏡像就已經做好了。


二,編譯bluez協議棧。

   移植過藍芽協議棧的人,肯定會覺得,Bluez協議棧的編譯是最麻煩的一件事情。其實,如果你能理清楚bluez-utils所依賴的一些庫,你就能很快的cross-compile交叉編譯出一套能在開發板上跑起來的程式。關鍵是如何去理清楚協議,我總結出來的方法是,倒著推,你不知道bluez-utils依賴那些庫,那就先直接編譯bluez-utils,根據編譯顯示的錯誤,分析錯誤,找出來它所依賴的庫,這樣一步一步的分析下去,你就可以把藍芽協議棧交叉編譯出來。如果你不會分析錯誤或則不想去分析,可以,那你就直接把錯誤粘貼到網上,讓搜尋引擎給你找。

由於時間的倉促,這裡我只列出我已經總結出來的Bluez所需要的幾個庫,以及幾個庫編譯的先後順序。


註:/opt/libs 和/opt/utils是我自己編譯時間用的路徑,你可以隨便的選取。

1,編譯安裝bluez-lib-3.36.tar.gz

   這個庫不需要什麼依賴,直接解壓,配置,編譯然後安裝即可。

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

  #./configure --profix=/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 --profix=/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 --profix=/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 c_cv_func_posix_getpwuid_r=yes>>arm-linux.cache

#echo ac_cv_func_posix_getgrgid_r=yes>>

注意:">"和">>"的區別

#./configure --profix=/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 --profix=/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 --profix=/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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.