Bluez交叉编译


参考: 【Bluetooth|蓝牙开发】十一、一文秒懂 | 超详细的Bluez交叉编译

依赖:

Bluez
glib
dbus
readline
Bluez
libffi
zlib
gettext
libiconv
expat
ncurses
  • Bluez官网:http://www.bluez.org/
  • GLib官网:https://docs.gtk.org/glib
  • libffi下载路径:https://github.com/libffi/libffi/releases/
  • zlib下载地址:http://zlib.net/zlib-1.2.12.tar.gz
  • D-Bus下载目录:https://dbus.freedesktop.org/releases/dbus/
  • Expat下载路径:https://libexpat.github.io/,https://github.com/libexpat/libexpat/releases
  • 下载地址:http://git.savannah.gnu.org/cgit/readline.git?h=devel
  • 下载地址:http://ftp.gnu.org/pub/gnu/ncurses

概览

下载Bluez

wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.65.tar.xz		# 下载Bluez
tar -xvf bluez-5.65.tar.xz			# 解压bluez
cd bluez-5.64/						# 进入目录	

安装Bluez的信息

进入到bluez-5.65后,查看README文件,可以看到其依赖项:

BlueZ - Bluetooth protocol stack for Linux
******************************************

Copyright (C) 2000-2001  Qualcomm Incorporated
Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>


Compilation and installation
============================

In order to compile Bluetooth utilities you need following software packages:
        - GCC compiler
        - GLib library
        - D-Bus library
        - udev library (optional)
        - readline (command line clients)

        On a debian based system, this can be done by running the following command:
                sudo apt-get build-dep bluez
                ./bootstrap

To configure run:
        ./configure --prefix=/usr --mandir=/usr/share/man \
                                --sysconfdir=/etc --localstatedir=/var

Configure automatically searches for all required components and packages.

安装Bluez,需要对其依赖项进行逐一安装,下面我们依次进行安装

安装步骤

先创建一个输出目录:

mkdir bluez_output
cd bluez_output
export bluez_output=/home/liefyuan/luckfox-pico-main/project/app/bluez/bluez_output		#设置环境变量

安装glib

交叉编译glib

安装Expat

Expat是一个用C编写的XML解析器库,是D-Bus守护进程所需的惟一依赖项。

Expat下载路径:

  • https://libexpat.github.io/
  • https://github.com/libexpat/libexpat/releases

Expat下载版本:expat-2.4.9.tar.xz

tar -xzvf expat-2.4.9.tar.gz
cd expat-2.4.9/
./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" --host=arm-rockchip830-linux-uclibcgnueabihf
make -j16
make install

此时,会在$bluez_output目录下,看到安装后所生成的lib和include的一些文件

--enable-selinux=no --without-x 是一些配置信息,不适用selinux和x11支持,否则可能会报错!

安装完expat库后,再安装D-bus!

安装D-Bus

D-Bus是一个用于进程间通信和协调的简单系统。

D-Bus下载目录:https://dbus.freedesktop.org/releases/dbus/

D-Bus下载版本:dbus-1.15.0.tar.xz

wget https://dbus.freedesktop.org/releases/dbus/dbus-1.15.0.tar.xz	# 下载
tar -xvf dbus-1.15.0.tar.xz				# 解压
cd dbus-1.15.0/							# 切换目录
./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" --host=arm-rockchip830-linux-uclibcgnueabihf --enable-selinux=no --without-x

make -j16								# 编译
make install							# 安装到对应目录

我们先不着急安装,查看一下README和INSTALL文件,发现D-bus的安装,必须依赖Expat库!

Requisite:

    Gettext
    expat

Optional:

    libselinux (for SELinux integration)
    doxygen (for API documentation)
    xmlto or meinproc4 (for Spec & other XML documentation)

make阶段报错1

/usr/include/glib-2.0/glib/gtypes.h: In function '_GLIB_CHECKED_ADD_U64':
/usr/include/glib-2.0/glib/gmacros.h:738:31: error: static assertion failed: "Expression evaluates to false"
 #define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
                               ^~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gtypes.h:463:3: note: in expansion of macro 'G_STATIC_ASSERT'
   G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
   ^~~~~~~~~~~~~~~

解决办法:https://blog.csdn.net/a6333230/article/details/122043012

sudo vim /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h
typedef signed long long gint64;    // typedef signed long gint64; liefyuan fix for glib cross compiler
typedef unsigned long long guint64; // typedef unsigned long guint64; liefyuan fix for glib cross compiler

#define G_GINT64_CONSTANT(val)  (val##L)
#define G_GUINT64_CONSTANT(val) (val##UL)
#define G_GINT64_MODIFIER "l"
#define G_GINT64_FORMAT "li"
#define G_GUINT64_FORMAT "lu"

#define GLIB_SIZEOF_VOID_P 8
#define GLIB_SIZEOF_LONG   8
#define GLIB_SIZEOF_SIZE_T 4  // 8 liefyuan fix
#define GLIB_SIZEOF_SSIZE_T 4 // 8 liefyuan fix 

编译、安装成功!!

安装readline

Readline库提供了一组供应用程序使用的函数,并且允许用户在输入命令行时编辑它们。

下载地址:http://git.savannah.gnu.org/cgit/readline.git?h=devel

下载版本:readline-8.2.tar.gz

wget http://git.savannah.gnu.org/cgit/readline.git/snapshot/readline-8.2.tar.gz
tar -xvf readline-8.2.tar.gz
cd readline-8.2/
./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" --host=arm-rockchip830-linux-uclibcgnueabihf bash_cv_wcwidth_broken=yes
make -j8
make install

安装ncurses

ncurses是readline所依赖的一个库

下载地址:http://ftp.gnu.org/pub/gnu/ncurses

下载版本:ncurses-6.3.tar.gz

wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.3.tar.gz
tar -zxvf ncurses-6.3.tar.gz 
cd ncurses-6.3/
./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib"  CXX="arm-rockchip830-linux-uclibcgnueabihf-g++" --host=arm-rockchip830-linux-uclibcgnueabihf --without-cxx --without-cxx-binding --without-ada --without-manpages --enable-overwrite --without-debug --without-tests --with-shared --without-tests --without-progs
make -j8
make install

安装ncurses出错

datadir=/home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share \
ticdir=/home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share/terminfo \
source=terminfo.tmp \
cross_compiling=yes \
/bin/sh ./run_tic.sh
** Building terminfo database, please wait...
Running tic to install /home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share/terminfo ...

	You may see messages regarding extended capabilities, e.g., AX.
	These are extended terminal capabilities which are compiled
	using
		tic -x
	If you have ncurses 4.2 applications, you should read the INSTALL
	document, and install the terminfo without the -x option.

ncurses 6.1.20180127
"terminfo.tmp", line 1152, col 36, terminal 'fbterm': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 5136, col 36, terminal 'xterm+256color': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 5168, col 36, terminal 'xterm+256setaf': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 5215, col 25, terminal 'xterm+direct2': limiting value of `colors' from 0x1000000 to 0x7fff
"terminfo.tmp", line 5215, col 40, terminal 'xterm+direct2': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 5230, col 25, terminal 'xterm+direct': limiting value of `colors' from 0x1000000 to 0x7fff
"terminfo.tmp", line 5230, col 40, terminal 'xterm+direct': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 5252, col 25, terminal 'xterm+indirect': limiting value of `colors' from 0x1000000 to 0x7fff
"terminfo.tmp", line 5252, col 40, terminal 'xterm+indirect': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 8248, col 36, terminal 'dvtm-256color': limiting value of `pairs' from 0x10000 to 0x7fff
"terminfo.tmp", line 5126, terminal 'xterm-16color': error writing /home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share/terminfo/x/xterm-16color
? tic could not build /home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share/terminfo
Makefile:109: recipe for target 'install.data' failed
make[1]: *** [install.data] Error 1
make[1]: Leaving directory '/home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/ncurses-6.3/misc'
Makefile:131: recipe for target 'install' failed
make: *** [install] Error 2

没有解决办法,我就把./misc/terminfo.tmp里面的两个部分注释掉了

#xterm-16color|xterm with 16 colors like aixterm,
#   ccc,
#   initc=\E]4;%p1%d;rgb:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*
#         %{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
#   use=xterm+osc104, use=ibm+16color, use=xterm-new,
# for liefyuan commit

...

#xterm-direct256|xterm with direct-colors and 256 indexed colors,
#   use=xterm+direct256, use=xterm,
# liefyuan commit

安装完ncurse后,我们再次安装readline,需要包含ncurse库!

cd readline-8.2/
./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" --host=arm-rockchip830-linux-uclibcgnueabihf bash_cv_wcwidth_broken=yes
make SHLIB_LIBS=-lncurses -j8
make install

安装Bluez

Bluez官网:http://www.bluez.org/
源码地址:www.kernel.org/pub/linux/bluetooth/bluez-5.65.tar.xz

手动下载后,看看README文件:

Compilation and installation
============================

In order to compile Bluetooth utilities you need following software packages:
    - GCC compiler
    - GLib library
    - D-Bus library
    - udev library (optional)
    - readline (command line clients)

    On a debian based system, this can be done by running the following command:
        sudo apt-get build-dep bluez
        ./bootstrap

To configure run:
    ./configure --prefix=/usr --mandir=/usr/share/man \
                --sysconfdir=/etc --localstatedir=/var

Configure automatically searches for all required components and packages.

To compile and install run:
    make && make install

完之后,我们就来安装最后的大Boss——``Bulez`

cd bluez-5.65/
mkdir output

./configure \
	--prefix=$bluez_output \
	CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" \
	PKG_CONFIG_PATH=$bluez_output/lib/pkgconfig \
	--host=arm-rockchip830-linux-uclibcgnueabihf \
	--disable-systemd \
	--disable-udev \
	--disable-cups \
	--disable-obex \
	--enable-library 

# 新写法
./configure \
	--prefix=$bluez_output \
	CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" \
	PKG_CONFIG_PATH=$bluez_output/lib/pkgconfig \
	--host=arm-rockchip830-linux-uclibcgnueabihf \
	--disable-systemd \
	--disable-udev \
	--disable-cups \
	--disable-obex \
	--enable-library 


./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib" PKG_CONFIG_PATH=$bluez_output/lib/pkgconfig --host=arm-rockchip830-linux-uclibcgnueabihf --disable-systemd --disable-udev --disable-cups --disable-obex --enable-library 
make SHLIB_LIBS=-lncurses -j8
make install

指定

./configure \
    --prefix=$bluez_output\
    --host=arm-rockchip830-linux-uclibcgnueabihf \
    CC="arm-rockchip830-linux-uclibcgnueabihf-gcc" \
    CFLAGS="-march=mips32r2 -muclibc -I$blue/include -I../dbus-1.12.20 -I$blue/src -L$blue/lib -L../dbus-1.12.20" \
    LDFLAGS=" -march=mips32r2 -muclibc " \
    LIBS="$blue/lib/libtermcap.a" \
    --disable-udev \
    --disable-test 
    CFLAGS="-march=mips32r2 -muclibc -I$blue/include -I../dbus-1.12.20 -I$blue/src -L$blue/lib -L../dbus-1.12.20" \
    LDFLAGS=" -march=mips32r2 -muclibc " \
    LIBS="$blue/lib/libtermcap.a" \

当前文件下面的Makefile是由./configure命令之后产生的!

configure阶段报错:

...
checking D-Bus configuration directory... /etc
checking D-Bus system bus services dir... /usr/share/dbus-1/system-services
checking D-Bus session bus services dir... /usr/share/dbus-1/services
${prefix}/share/zsh/site-functions
checking for readline/readline.h... no
configure: error: readline header files are required
liefyuan@ubuntu:~/rv1103/luckfox-pico-main/project/app/bluez/bluez-5.65$ find ~/rv1103/luckfox-pico-main/project/app/ -name "readline.h"
/home/liefyuan/rv1103/luckfox-pico-main/project/app/bluez/bluez_output/include/readline/readline.h
/home/liefyuan/rv1103/luckfox-pico-main/project/app/bluez/bluez-5.65/android/compat/readline/readline.h

头文件是在bluez_output/include/readline/readline.h


4.4.1 ncurses

ncurses是readline所依赖的一个库

下载地址:http://ftp.gnu.org/pub/gnu/ncurses

下载版本:ncurses-6.3.tar.gz

wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.3.tar.gz
tar -zxvf ncurses-6.3.tar.gz 
cd ncurses-6.3/
./configure --prefix=$bluez_output CC="arm-linux-gnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib"  CXX="arm-linux-gnueabihf-g++" --host=arm-linux-gnueabihf --without-cxx --without-cxx-binding --without-ada --without-manpages --enable-overwrite --without-debug --without-tests --with-shared --without-tests --without-progs
make -j8
make install

安装完ncurse后,我们再次安装readline,需要包含ncurse库!

4.4.2 readline

编译安装 bluez

将ncurses安装后,再次回到bluez,执行安装步骤,并且引入ncurses库!

cd bluez-5.65/
mkdir output
./configure --prefix=$bluez_output CC="arm-rockchip830-linux-uclibcgnueabihf-gcc -I$bluez_output/include -L$bluez_output/lib -lncurses" PKG_CONFIG_PATH=$bluez_output/lib/pkgconfig --host=arm-rockchip830-linux-uclibcgnueabihf --disable-systemd --disable-udev --disable-cups --disable-obex --enable-library
make -j8
make install

configure报错:

checking D-Bus configuration directory... /home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/etc
checking D-Bus system bus services dir... /home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share/dbus-1/system-services
checking D-Bus session bus services dir... /home/liefyuan/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez_output/share/dbus-1/services
${prefix}/share/zsh/site-functions
checking for readline/readline.h... yes
checking for rst2man... no
checking for rst2man.py... no
configure: error: rst2man is required

解决办法:

sudo apt -y install python-docutils

make 出错:

src/shared/shell.c:25:10: fatal error: wordexp.h: No such file or directory
 #include <wordexp.h>
          ^~~~~~~~~~~
compilation terminated.
Makefile:8016: recipe for target 'src/shared/libshared_mainloop_la-shell.lo' failed
make[1]: *** [src/shared/libshared_mainloop_la-shell.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
Makefile:4358: recipe for target 'all' failed
make: *** [all] Error 2

我找了一下,是有这个头文件的

~/rv1103/luckfox-pico-main-origin/project/app/bluez/bluez-5.65$ sudo find ./ -name "wordexp.h"
./android/compat/wordexp.h

简单一点的方法是什么?

就是通过构建工具来编译,直接通过类似于buildroot等类似的构建工具,直接选中bluez的外部包,直接编译也可以的:)

相关推荐

  1. Bluez交叉编译

    2024-01-09 11:00:03       41 阅读
  2. 交叉编译

    2024-01-09 11:00:03       17 阅读
  3. 交叉编译代码

    2024-01-09 11:00:03       20 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-09 11:00:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-09 11:00:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-09 11:00:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-09 11:00:03       20 阅读

热门阅读

  1. C++ STL中vector的模拟实现

    2024-01-09 11:00:03       36 阅读
  2. 安卓adb

    2024-01-09 11:00:03       33 阅读
  3. 逐步递进地手写一个Promise

    2024-01-09 11:00:03       31 阅读
  4. 探索 GitHub:高效使用技巧与实例分享

    2024-01-09 11:00:03       40 阅读
  5. git常用指令及应用案例

    2024-01-09 11:00:03       43 阅读
  6. 程序员必备的面试技巧

    2024-01-09 11:00:03       36 阅读
  7. Django创建RSS订阅

    2024-01-09 11:00:03       36 阅读