背景
由于需要在嵌入式主板运行freeswitch, 故需将其交叉编译运行在arm平台上。在网上找了一通均无实现方式。只好先学习一下autoconf, automake和libtool,然后拿apr练一下如何交叉编译。此文参考了apche2移植到Arm开发板的过程。我的主机是WIN10,安装了wsl和ubuntu18。另外使用windows商店安装的terminal工具,非常方便在windows中开发linux系统。
准备工作
- 下载交叉编译链
- 我使用的是arm-linux-gnueabihf,具体下载请网上查询
- 先更新一下安装源,避免下载更新失败,请查看:更新国内下载源
- 使用如下命令安装:
-
sudo apt-get install gcc-arm-linux-gnueabihf
如上安装完后,将会自动 配置好路径,此时可以通过如下命令验证是否有效:
-
arm-linux-gnueabihf-gcc -v Using built-in specs. COLLECT_GCC=arm-linux-gnueabihf-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/7/lto-wrapper Target: arm-linux-gnueabihf Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include Thread model: posix gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
- freeswitch1.8.x下载地址下载APR和APR-Util
- 我使用freeswitch源代码包中的apr版本,下载地址:freeswitch1.8下载地址
编译APR
首先在apr源代码根目录下创建arm-linux.cache文件,内容如下:
ac_cv_file__dev_zero=yes
ac_cv_func_setpgrp_void=yes
apr_cv_tcp_nodelay_with_cork=yes
#下面根据具体系统环境添加
apr_cv_process_shared_works=yes
apr_cv_mutex_robust_shared=yes
其次修改configure.ac文件:(主要增加av_cv_sizeof_long_long判断,否则make会报错)
if test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then
ssize_t_fmt='#define APR_SSIZE_T_FMT "d"'
elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long"; then
ssize_t_fmt='#define APR_SSIZE_T_FMT "ld"'
elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long_long"; then
ssize_t_fmt='#define APR_SSIZE_T_FMT "lld"'
else
ssize_t_fmt='#error Can not determine the proper size for ssize_t'
fi
if test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then
size_t_fmt='#define APR_SIZE_T_FMT "d"'
elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long"; then
size_t_fmt='#define APR_SIZE_T_FMT "ld"'
elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long_long"; then
size_t_fmt='#define APR_SIZE_T_FMT "lld"'
else
size_t_fmt='#define APR_SIZE_T_FMT "zu"'
fi
修改完后执行如下命令更新configure脚本
autoconf
交叉编译的命令如下:
./configure --prefix=/usr/local/apr --host=arm-linux-gnueabihf --cache=arm-linux.cache
编译安装:
make
make install
编译APR-Util
由于源文件默认不带dbd/apr-mysql.c文件(如果要下载请参考INSTALL.MYSQL文件),故需要修改configure.ac文件:(注释掉MYSQL的检查)
APU_CHECK_DBD
dnl APU_CHECK_DBD_MYSQL
APU_CHECK_DBD_SQLITE3
APU_CHECK_DBD_SQLITE2
然后运行如下命令:
autoconf
./configure --prefix=/usr/local/apr --with-apr=/usr/local/apr --host=arm-linux-gnueabihf
make && make install