二、准备工作
1. 编译环境
- 宿主机:
Ubuntu 20.04.6 LTS - Host:ARM32位
- 交叉编译器:
arm-linux-gnueabihf-gcc-11.1.0
2. 设置交叉编译工具链
在交叉编译之前,需要设置交叉编译工具链的环境变量。
bash
export PATH=/path/to/toolchains/arm-linux-gnueabihf/bin:$PATH
三、交叉编译libsbc
1. 下载源码
下载并解压源码(以sbc2.1为例):
bash
git clone git://git.kernel.org/pub/scm/bluetooth/sbc.git sbc-2.1
cd sbc-2.1
2. 生成configure配置
sbc源码没有configure文件,需要手动生成。
生成 configure:
bash
autoreconf -fi
输出示例:
bash
yoyo@yoyo:/media/sda3/360Downloads/sbc-2.1$ autoreconf -fi
aclocal: warning: couldn't open directory 'build-aux': No such file or directory
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build-aux'.
libtoolize: copying file 'build-aux/libtool.m4'
libtoolize: copying file 'build-aux/ltoptions.m4'
libtoolize: copying file 'build-aux/ltsugar.m4'
libtoolize: copying file 'build-aux/ltversion.m4'
libtoolize: copying file 'build-aux/lt~obsolete.m4'
configure.ac:21: installing 'build-aux/compile'
configure.ac:26: installing 'build-aux/config.guess'
configure.ac:26: installing 'build-aux/config.sub'
configure.ac:8: installing 'build-aux/install-sh'
configure.ac:8: installing 'build-aux/missing'
Makefile.am: installing 'build-aux/depcomp'
生成configure配置:
bash
./configure \
--host=arm-linux-gnueabihf \
--prefix=/media/sda3/360Downloads/sbc-2.1/arm_install \
--enable-shared \
--disable-static \
--disable-tools \
--disable-tester \
CC=arm-linux-gnueabihf-gcc
输出示例:
bash
yoyo@yoyo:/media/sda3/360Downloads/sbc-2.1$ ./configure \
> --host=arm-linux-gnueabihf \
> --prefix=/media/sda3/360Downloads/sbc-2.1/arm_install \
> --enable-shared \
> --disable-static \
> --disable-tools \
> --disable-tester \
> CC=arm-linux-gnueabihf-gcc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-linux-gnueabihf-strip... arm-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to create a pax tar archive... gnutar
checking whether make supports nested variables... (cached) yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for arm-linux-gnueabihf-gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabihf-gcc accepts -g... yes
checking for arm-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking whether arm-linux-gnueabihf-gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of arm-linux-gnueabihf-gcc... gcc3
checking whether arm-linux-gnueabihf-gcc accepts -fPIE... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-gnueabihf
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by arm-linux-gnueabihf-gcc... /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld
checking if the linker (/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -B
checking the name lister (/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to arm-unknown-linux-gnueabihf format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld option to reload object files... -r
checking for arm-linux-gnueabihf-objdump... arm-linux-gnueabihf-objdump
checking how to recognize dependent libraries... pass_all
checking for arm-linux-gnueabihf-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for arm-linux-gnueabihf-ar... arm-linux-gnueabihf-ar
checking for archiver @FILE support... @
checking for arm-linux-gnueabihf-strip... (cached) arm-linux-gnueabihf-strip
checking for arm-linux-gnueabihf-ranlib... arm-linux-gnueabihf-ranlib
checking command to parse /home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-nm -B output from arm-linux-gnueabihf-gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for arm-linux-gnueabihf-mt... no
checking for mt... mt
configure: WARNING: using cross tools not prefixed with host triplet
checking if mt is a manifest tool... no
checking how to run the C preprocessor... arm-linux-gnueabihf-gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if arm-linux-gnueabihf-gcc supports -fno-rtti -fno-exceptions... no
checking for arm-linux-gnueabihf-gcc option to produce PIC... -fPIC -DPIC
checking if arm-linux-gnueabihf-gcc PIC flag -fPIC -DPIC works... yes
checking if arm-linux-gnueabihf-gcc static flag -static works... yes
checking if arm-linux-gnueabihf-gcc supports -c -o file.o... yes
checking if arm-linux-gnueabihf-gcc supports -c -o file.o... (cached) yes
checking whether the arm-linux-gnueabihf-gcc linker (/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating sbc/sbc.pc
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
sbc 2.1
3. 编译安装
bash
make -j$(nproc)
make install
make 编译:
bash
yoyo@yoyo:/media/sda3/360Downloads/sbc-2.1$ make -j8
make --no-print-directory all-am
CC sbc/sbc_primitives.lo
CC sbc/sbc.lo
CC sbc/sbc_primitives_sse.lo
CC sbc/sbc_primitives_mmx.lo
CC sbc/sbc_primitives_iwmmxt.lo
CC sbc/sbc_primitives_neon.lo
CC sbc/sbc_primitives_armv6.lo
CCLD sbc/libsbc.la
make install 安装:
bash
yoyo@yoyo:/media/sda3/360Downloads/sbc-2.1$ make install
/usr/bin/mkdir -p '/media/sda3/360Downloads/sbc-2.1/arm_install/lib'
/bin/bash ./libtool --mode=install /usr/bin/install -c sbc/libsbc.la '/media/sda3/360Downloads/sbc-2.1/arm_install/lib'
libtool: install: /usr/bin/install -c sbc/.libs/libsbc.so.1.3.1 /media/sda3/360Downloads/sbc-2.1/arm_install/lib/libsbc.so.1.3.1
libtool: install: (cd /media/sda3/360Downloads/sbc-2.1/arm_install/lib && { ln -s -f libsbc.so.1.3.1 libsbc.so.1 || { rm -f libsbc.so.1 && ln -s libsbc.so.1.3.1 libsbc.so.1; }; })
libtool: install: (cd /media/sda3/360Downloads/sbc-2.1/arm_install/lib && { ln -s -f libsbc.so.1.3.1 libsbc.so || { rm -f libsbc.so && ln -s libsbc.so.1.3.1 libsbc.so; }; })
libtool: install: /usr/bin/install -c sbc/.libs/libsbc.lai /media/sda3/360Downloads/sbc-2.1/arm_install/lib/libsbc.la
libtool: finish: PATH="/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin:/home/yoyo/.local/bin:/home/yoyo/360Downloads/cmake-3.31.3-linux-x86_64/bin:/home/yoyo/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin" ldconfig -n /media/sda3/360Downloads/sbc-2.1/arm_install/lib
----------------------------------------------------------------------
Libraries have been installed in:
/media/sda3/360Downloads/sbc-2.1/arm_install/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/mkdir -p '/media/sda3/360Downloads/sbc-2.1/arm_install/lib/pkgconfig'
/usr/bin/install -c -m 644 sbc/sbc.pc '/media/sda3/360Downloads/sbc-2.1/arm_install/lib/pkgconfig'
/usr/bin/mkdir -p '/media/sda3/360Downloads/sbc-2.1/arm_install/include/sbc'
/usr/bin/install -c -m 644 sbc/sbc.h '/media/sda3/360Downloads/sbc-2.1/arm_install/include/sbc'
4. 设置pkg-config
bash
export PKG_CONFIG_PATH=/media/sda3/360Downloads/sbc-2.1/arm_install/lib/pkgconfig:$PKG_CONFIG_PATH