freeswitch之源码安装

本文详述了在Ubuntu 22.04.1虚拟机上通过源码安装FreeSwitch的过程,包括安装依赖库、解决编译错误和安装问题。涉及的依赖包括spandsp、sofia-sip、sqlite3、libcurl、libpcre等。文章还提供了针对-Werror隐式声明、过时声明、pedantic错误等问题的解决方法,并给出了编译时遇到的uuid相关问题的解决策略。最后,列举了安装过程中可能遇到的其他问题及其解决思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    在Ubuntu(虚拟机)上多次使用源码方式安装freeSwitch软件,由于freeSwitch在编译中依赖很多软件和工具,再加上系统版本和软件源的原因,每一次安装都遇到很多问题,花费大量时间排查,因此,本文记录一下安装过程和一些问题的解决方法。

注:文中使用操作系统版本Ubuntu 22.04.1(虚拟机),其它版本操作系统安装流程和问题解决方法类似。

一、环境安装

1.安装常用包

sudo apt install autoconf libtool-bin g++ pkg-config libtiff-dev
2. 安装libtiff-dev
sudo apt install libtiff-dev

3. 安装spandsp
# git clone https://github.com/freeswitch/spandsp.git
# cd spandsp
# ./bootstrap.sh -j
# ./configure
# make
# sudo make install
# ldconfig


4. 安装sofia-sip
no usable sofia-sip; please install sofia-sip-ua devel package or equivalent
# git clone https://github.com/freeswitch/sofia-sip.git
#cd sofia-sip
# ./bootstrap.sh -j
# ./configure
# make
# make install0
# ldconfig


5. 安装sqlite3
解决方法: sudo apt install libsqlite3-dev
          sudo apt install sqlite3

6. 安装libcurl
sudo apt install libcurl4-nss-dev

7. 安装pcre
sudo apt install libpcre3-dev

8. 安装speexdsp
sudo apt install libspeexdsp-dev

9. 安装libldns
sudo apt install libldns-dev 

10. install libks or disable mod_verto in modules.conf
禁用mod_verto

11. install libks or disable mod_signalwire
禁用mod_signalwire

12. 安装libedit-dev
sudo apt install libedit-dev

13. 安装yasm
sudo apt install yasm

14. 安装uuid和uuid-dev
sudo apt install uuid
sudo apt install uuid-dev

默认安装后,uuid.h 在/usr/include/linux/目录下,而freeswitch源码引用目录是uuid, 因此需要建立/usr/include/uuid目录

$mkdir /usr/include/uuid
$cp /usr/include/linux/uuid.h /usr/include/uuid/

15. apt install libopus-dev

16. sudo apt install libsndfile-dev

二、下载编译

2.1 下载源码
方式一:  github下载
freeSwitch源码下载地址:https://github.com/signalwire/freeswitch
git clone https://github.com/signalwire/freeswitch

注:使用git下载可能会出现异常中断,可以在网页上使用zip包下载的方式

方式二: 文件服务网站下载
也可以通过下面的网站下载源码
 http://files.freeswitch.org/releases/freeswitch/
 
方式三:  其它下载方式(如gitee等)

2.2 编译
步骤1: sudo ./bootstrap.sh

步骤2:sudo ./configure

步骤3:sudo make
   

 编译错误处理:
   1. -Werror=implicit-function-declaration错误
       示例:src/switch_apr.c:1134:9: error: implicit declaration of function ‘uuid_unparse_lower’ [-Werror=implicit-function-declaration]
        解决方法: 修改Makefile中CFLAGS一行,忽略错误
           CFLAGS = -g -O2 -Wno-error=implicit-function-declaration 

  2. -Werror=deprecated-declarations错误
  解决方法: 修改Makefile中CFLAGS一行,忽略错误
  CFLAGS = -g -O2 -Wno-error=implicit-function-declaration -Wno-error=deprecated-declarations

  3. -Werror=pedantic错误
  解决方法: 修改Makefile中CFLAGS一行,忽略错误
  CFLAGS = -g -O2 -Wno-error=implicit-function-declaration -Wno-error=deprecated-declarations
  
  4. 禁用一些模块
     比如mode_lua、mod_opus、mod_pgsql、mod_skinny等
     
2.3 安装:
    $ sudo make install

默认安装目录:/usr/local/freeswitch
voip@voip-virtual-machine:/usr/local/freeswitch$ tree -L 1
.
├── bin
├── conf
├── db
├── fonts
├── grammar
├── htdocs
├── images
├── include
├── lib
├── log
├── mod
├── recordings
├── run
└── scripts

2.4 启动freeswitch
进入到安装目录,启动程序。也可以在其它目录使用绝对路径启动
voip@voip-virtual-machine:/usr/local/freeswitch$ ./bin/freeswitch

2.5 终端注册
使用sip终端注册已有账号1000(默认密码1234,默认端口5060)成功。如果一切正常,那么恭喜你,你已经完成基本的安装了。

三、安装问题的解决思路

一般是软件或库找不到,有三种解决方法
1. 使用apt install安装
2. 从github或gitee上下载源码进行编译安装

注:freeswitch可以通过编辑module.conf文件禁用相关模块

四、安装过程中遇到的问题及解决方法

  • 1. build-requirements: autoconf not found.

解决方法: sudo apt install autoconf

  • 2. build-requirements: libtool not found.

解决方法: sudo apt install libtool-bin

  • 3. 缺少spandsp

# git clone https://github.com/freeswitch/spandsp.git
# cd spandsp
# ./bootstrap.sh -j
# ./configure
# make
# make install
# ldconfig

  • 4.缺少sofia-sip

no usable sofia-sip; please install sofia-sip-ua devel package or equivalent
# git clone https://github.com/freeswitch/sofia-sip.git
#cd sofia-sip
# ./bootstrap.sh -j
# ./configure
# make
# make install
# ldconfig

  • 5. fatal error: openssl/ssl.h: No such file or directory

解决方法: sudo apt install libssl-dev

  • 6. Package sqlite3 was not found

解决方法: sudo apt install libsqlite3-dev
                 sudo apt install sqlite3

  • 7. libcurl was not found

       解决方法: sudo apt install libcurl4-nss-dev

  • 8. Package libpcre was not found 

         解决方法: sudo apt install libpcre3-dev

  • 9. Package speex was not found 

             sudo apt install libspeexdsp-dev

  • 10. You need to either install libldns-dev or disable mod_enum in modules.conf

          解决方法: sudo apt install libldns-dev 

  • 11. You need to either install libks or disable mod_verto in modules.conf

            方法一:下载安装 https://github.com/signalwire/libks.git

            方法二:禁用mod_verto
                  sudo vim modules.conf 
                  #endpoints/mod_verto

  • 12. error: You need to either install libedit-dev

                解决方法: sudo apt install libedit-dev

  • 13. 缺少yasm

                 解决方法: sudo apt install yasm

  • 14. You need to either install signalwire-client-c

                方法一:下载编译安装: https://github.com/signalwire/signalwire-c.git

                方法二: 注释掉modules.conf中的signalwire模块

  • 15. 编译错误

                ./include/apr_general.h:33:14: error: ‘__DARWIN_NSIG’ undeclared here (not in a function)
                33 | #define NSIG __DARWIN_NSIG
注: 没找到原因,发现没有代码使用该定,直接将该行定义注释掉

  • 16. 接口过期编译错误

错误1:

In file included from src/switch_apr.c:79:
/usr/include/openssl/md5.h:49:27: note: declared here
   49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
      |                           ^~~~~~~~
src/switch_apr.c:1177:9: warning: ‘MD5_Update’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
 1177 |         MD5_Update(&md5_context, input, inputLen);

解决方法:关闭接口过期警告

               sudo vim Makefile
              CFLAGS = -g -O2 -Wno-error=deprecated-declarations

错误2:

skinny_protocol.c:685:65: error: array subscript ‘skinny_message_t {aka struct skinny_message}[0]’ is partly outside array bounds of ‘unsigned char[292]’ [-Werror=array-bounds]
CFLAGS = -g -O2 -Wno-error=deprecated-declarations -Wno-error=array-bounds

解决方法:关闭相应告警

               sudo vim Makefile
              CFLAGS = -g -O2  -Wno-error=array-bounds

  • 17. 没有libavformat-dev and libswscale-dev

Makefile:1481: *** You must install libavformat-dev and libswscale-dev to build mod_av.  Stop.

解决方法:
sudo apt install libavformat-dev
sudo apt install libswscale-dev

注: 如果编译时还提示找不到,需要重新执行sudo ./configure

  • 18 缺少libtiff

configure: error: "Cannot build without libtiff (does your system require a libtiff-devel package?)"

解决方法:sudo apt install libtiff-dev

  • 19 缺少uuid

src/switch_apr.c:81:10: fatal error: uuid/uuid.h: No such file or directory

解决方法:

 sudo apt install uuid

 如果依旧找不到,查看 一下uuid.h文件的位置, 在笔者环境中,如下

$ ls /usr/include/linux/uuid.h 
/usr/include/linux/uuid.h

可以看出uuid.h在linux目录下,只要相应的创建/usr/lnclude/uuid目录,并将linux/uuid.h拷贝过去可以了

  • 20 找不到uuid_xx函数

/usr/bin/ld: ./.libs/libfreeswitch.so: undefined reference to `uuid_parse'
/usr/bin/ld: ./.libs/libfreeswitch.so: undefined reference to `uuid_unparse_lower'
/usr/bin/ld: ./.libs/libfreeswitch.so: undefined reference to `uuid_generate'

解决方法:sudo apt install uuid-dev

<think>嗯,用户现在遇到了一个编译错误,主要是链接器报错,说libswap.so和libfaker.so与aarch64linux不兼容。我需要先理解这个错误的根本原因。 首先,用户提供的命令行是一个Android NDK的编译命令,使用clang++来编译native-lib.cpp,并链接两个预编译的.so文件。但链接时ld.lld报错,提示这两个库与目标架构不兼容。目标架构是aarch64-none-linux-android23,也就是ARM64-v8a,Android API 23。 可能的第一个原因是这两个.so文件本身编译时的架构不对。比如,它们可能是为x86_64或者ARMv7编译的,而不是ARM64。用户需要确认这些库是否确实是为arm64-v8a构建的。另外,检查它们的编译工具链是否正确,是否使用了正确的NDK版本和参数。 其次,检查.so文件是否正确放置在了jniLibs/arm64-v8a目录下。如果目录结构错误,或者库文件放错了位置,可能会导致链接器无法正确识别架构。不过,用户已经放在arm64-v8a目录下,所以可能问题出在库文件本身。 接下来,可能需要用户使用file命令或者readelf工具来查看.so文件的ELF头信息,确认其目标架构是否为AArch64。例如,在Linux上运行file libswap.so,应该显示ELF 64-bit LSB shared object, ARM aarch64。 另一个可能性是编译这两个库时使用的NDK版本与当前项目中的NDK版本不一致。不同版本的NDK可能有不同的ABI要求,导致兼容性问题。用户需要确保所有库都使用相同版本的NDK编译。 此外,检查链接器参数是否正确。用户是否在CMakeLists.txt或者build.gradle中正确指定了目标ABI?比如,是否在ndk中指定了abiFilters 'arm64-v8a',确保只构建该架构的库。 如果确认库文件架构正确,可能需要检查是否有符号冲突或者其他链接问题。但根据错误信息,主要问题还是架构不兼容,所以重点应放在库的编译过程和架构匹配上。 另外,用户使用的NDK版本是27.0.12077983,这个版本可能较新,但有时新版本的NDK可能会有一些变更,导致旧库不兼容。可以尝试使用与编译这些.so文件相同的NDK版本来重新编译项目,看看是否能解决问题。 总结下来,用户需要做的是: 1. 检查.so文件的架构是否正确。 2. 确保所有库使用相同NDK版本编译。 3. 检查项目配置中的ABI设置。 4. 可能需要重新编译依赖库以匹配当前NDK和目标架构。</think>--- ### **问题分析** 你遇到的编译错误是由于链接器(`ld.lld`)发现预编译的 `.so` 文件(`libswap.so` 和 `libfaker.so`)与目标架构 **`aarch64`** 不兼容。具体表现为: ```bash ld.lld: error: ../../../../src/main/jniLibs/arm64-v8a/libswap.so is incompatible with aarch64linux ld.lld: error: ../../../../src/main/jniLibs/arm64-v8a/libfaker.so is incompatible with aarch64linux ``` 这意味着这两个动态库的**编译架构与当前目标架构(ARM64-v8a)不匹配**。 --- ### **根本原因** 1. **ABI 不匹配** - `libswap.so` 和 `libfaker.so` 可能是为其他架构(如 `armeabi-v7a`、`x86_64`)编译的,而非 `arm64-v8a`。 - 检查库文件的编译命令或来源,确认其目标架构是否为 `arm64-v8a`。 2. **NDK 版本冲突** - 若这些库是用旧版本 NDK 编译的,而当前项目使用 NDK 27,可能因工具链差异导致兼容性问题。 3. **ELF 格式问题** - 某些预编译库可能未遵循 Android 的 ELF 格式规范(例如未正确设置 `SONAME` 或符号表)。 --- ### **解决方案** #### **步骤 1:验证 `.so` 文件的架构** 使用 `file` 命令或 `readelf` 检查库文件的架构: ```bash # 在 Linux 或 WSL 中执行 file libswap.so # 正确输出应为:ELF 64-bit LSB shared object, ARM aarch64 ``` 如果输出显示 `ARM aarch64`,则文件架构正确;若显示 `32-bit` 或其他架构(如 `x86-64`),需重新编译库。 #### **步骤 2:重新编译依赖库** 若库文件架构错误,需用 **相同 NDK 版本** 和 **目标架构** 重新编译: 1. 确保 `CMakeLists.txt` 或 `Android.mk` 中指定 `arm64-v8a`: ```cmake # CMake 示例 set(ANDROID_ABI "arm64-v8a") ``` 2. 使用 NDK 27 的 `clang++` 重新编译库: ```bash # 替换为你的源码路径 E:\SDK\ndk\27.0.12077973\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe \ --target=aarch64-none-linux-android23 \ -fPIC -shared \ -o libswap.so swap.cpp ``` #### **步骤 3:检查 NDK 版本一致性** - 确保所有依赖库(如 `libswap.so`、`libfaker.so`)均使用 **NDK 27** 编译。 - 若库来自第三方,需确认其是否支持 NDK 27 和 `arm64-v8a`。 #### **步骤 4:清理并重新构建项目** 1. 删除构建缓存: ```bash ./gradlew clean ``` 2. 重新构建: ```bash ./gradlew assembleDebug --stacktrace ``` --- ### **关键注意事项** 1. **ABI 目录结构** - 确保 `.so` 文件放置在 `src/main/jniLibs/arm64-v8a` 目录下,而非通用 `libs` 目录。 2. **NDK 工具链配置** - 在 `app/build.gradle` 中指定 NDK 版本和 ABI: ```groovy android { ndkVersion "27.0.12077973" defaultConfig { ndk { abiFilters "arm64-v8a" } } } ``` 3. **符号表兼容性** - 若库包含 C++ 代码,需确保所有库使用相同的 **STL 实现**(如 `c++_shared`)。 --- ### **扩展:常见 ABI 不兼容场景** | **现象** | **解决方案** | |-------------------------|------------------------------------------| | 32 位库混用 64 位环境 | 重新编译为 `arm64-v8a` 或 `x86_64` | | NDK 版本不一致 | 统一所有依赖库的 NDK 版本 | | 缺少依赖符号 | 检查库的依赖关系(`ldd` 或 `readelf -d`)| --- ### **总结** 1. 核心问题是预编译库的 **架构与目标 ABI 不匹配**。 2. 优先重新编译依赖库,确保使用 **相同 NDK 版本** 和 **arm64-v8a 架构**。 3. 若问题持续,检查 NDK 配置和构建脚本的完整性。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪游东戴河

你就是这个世界的唯一

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值