为iOS编译Sofia-SIP

时间:2014-05-14 06:45:43

标签: ios arm clang cross-compiling sofia-sip

我正在尝试为架构armv6armv7编译iOS Sofia-SIP library,但我遇到了问题。以下是我正在做的事情。

export DEVROOT=/Applications/Xcode_4_6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer    
export SDKROOT=$DEVROOT/SDKs/iPhoneOS6.1.sdk    
export CC=$SDKROOT/usr/bin/llvm-gcc-4.2    
export CFLAGS="-pipe -no-cpp-precomp -isysroot $SDKROOT -arch armv7"    
export LDFLAGS="-syslibroot $SDKROOT -arch armv7"    
export CPP=$SDKROOT/usr/bin/llvm-g++-4.2./configure --host=arm-apple-darwin10    
sudo ./configure --host=arm-apple-darwin10

RESULT

Password:    
configure: WARNING: if you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used    
checking build system type... x86_64-apple-darwin12.5.0    
checking host system type... arm-apple-darwin10    
checking target system type... arm-apple-darwin10    
checking cached information... ok    
checking for a BSD-compatible install... /usr/bin/install -c    
checking whether build environment is sane... yes    
checking for gawk... gawk    
checking whether make sets $(MAKE)... yes    
checking for arm-apple-darwin10-strip... no    
checking for strip... strip    
checking whether to enable maintainer-specific portions of Makefiles... no    
checking for style of include used by make... GNU    
checking for arm-apple-darwin10-gcc... no    
checking for gcc... gcc    
checking for arm-apple-darwin10-gcc... gcc    
checking whether the C compiler works... yes

问题

我希望脚本使用llvm-gcc编译器。但是它正在寻找它找不到的arm-apple-darwin10-gcc,然后最终使用gcc编译器。

2 个答案:

答案 0 :(得分:3)

我和这个人一起度过了一个周末,赢得了这场战斗(得到了很多帮助),并有以下几点回到社区:

  1. 关于 su_os_nw.c
    SCDynamicStore: function has been explicitly marked unavailable for iOS 问题:

    我正要放弃,但注意到来自Restcomm的一位名叫Antonis Tsakirids的人reported success in integrating Sofia in their iOS SDK。 然后我去了他们的git仓库和had a look at their SDK

    在/ dependencies / sofia-sip / libsofia-sip-ua / su /我找到了罪魁祸首: su_os_nw.c

  2. 他们优雅地更新了

    #if defined (__APPLE_CC__)
    

    #if defined (__APPLE_CC__) && !defined(TARGET_OS_IPHONE)
    

    这解决了它......

    1. ...但它本身并没有解决它...因为显然since Xcode 7, Apple did some toolchain utilities shuffling。 东西不再位于“通常”的位置,MishaBruckman的$ DEVROOT已经过时了。
      例如,我收到有关“ar”未找到的错误。
    2. export DEVROOT =" $(xcrun --sdk iphoneos --show-sdk-platform-path)/ Developer“
      映射到 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer

      但是,工具链实用程序(ld,ar,as,nm,ranlib以及全能铿锵声)已移至 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain 在/ usr / bin中。 我将应该映射到新$ DEVROOT的部分加粗。

      希望这有助于某人节省2周末的生活......

      ......最后,上面提到的2点不足以走出困境......编译确实完成了,我最初离开了它。

      但是,今天我想实际使用该库。创建了一个新项目,导入了库,点击了Build ...更多的痛苦......

      libsofia-sip-ua.a does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target for architecture armv7.
      

      起初我去了“说哇......”?

      • 关于在Xcode中设置内容的mumbo_jumbo是什么?我用old_school的方式做了一些事情,在命令行编译......

      • 你是什么意思“从供应商那里获得一个更新的库”......“供应商”就是我,我正在建立这个库......

      • 无论如何,这个奇怪的bitcode是什么?

      在完成关于bitcode的作业后,我开始想知道Xcode的ENABLE_BITCODE背后隐藏着什么...原来它“意味着”将“-fembed-bitcode”标志传递给clang。

      总之,行

      export CFLAGS="-arch ${ARM_ARCH} -mios-version-min=7 -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${SDKROOT}/usr/include/"
      

      成了

      export CFLAGS="-arch ${ARM_ARCH} -mios-version-min=7 -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${SDKROOT}/usr/include/"
      

      使用新设置重建Sofia,但后来它开始抱怨即使主项目本身没问题,它的子库(例如libstun.a)也没有用bitcode编译。 A"干净"摆脱旧垃圾和编译完成好了。将新生成的lib导入到我的Xcode项目中,一切都很好。

      最终得出结论。在2015年的anno domini中整合索菲亚图书馆的Xcode 7 / iOS9下的项目建设成功......

      ...... aaaand ......我还没有走出困境......

      我决定在项目中添加 arm64 架构后,Xcode再次开始抱怨Sofia:

      ignoring file libsofia-sip-ua.a, file was built for archive which is not the architecture being linked (arm64)
      Undefined symbols for architecture arm64
      

      非常简单,我想:我只是将 armv7 替换为 arm64

      export ARM_ARCH="arm64”
      

      在修改之后,遇到了灾难./configureing:

      checking for gcc... /usr/bin/clang
      checking for gcc... (cached) /usr/bin/clang
      checking whether the C compiler works... no
      configure: error: in `/work/fromSourceforge/sofia-sip-1.12.11':
      configure: error: C compiler cannot create executables
      See `config.log' for more details
      

      第二天花了很多时间搞清楚是什么问题(我不能./不再配置,甚至回到armv7)

      • 冲击堆栈溢出;没有解决方案帮助

      • 选中广告重新检查系统上的每条路径......我惊讶地发现,在整个macosx中,人们可以在3-4个地方找到clang和gcc,但我离题了......

      • 尝试重新安装Xcode Developer Tools

      • 最终重新安装Xcode本身......

      ......没什么帮助。

      一位眼尖的同事发现了错误:

      导出ARM_ARCH = " arm64“

      最后一个引号不是"相同"作为第一个引号。第一个引号是"正确的引号#34; 即使我没有用自己的手触摸第二个,当我将v7转换为64时,TextEdit会自行更改它。显然它是一个功能",称为SmartQuotes。顺便说一下,我无法禁用它 心理记录:永远不要再使用TextEdit来编辑.bash_profile文件。

      最后,我发现自己处于64位版Sofia的位置。将它插入我的Xcode项目,aaaaaa ....

      ignoring file libsofia-sip-ua.a, file was built for archive which is not the architecture being linked (armv7)
      Undefined symbols for architecture armv7
      

      嗯...如果我用32位构建它,它会抱怨64个丢失...如果我为64位构建它,它会抱怨大约32个...

      事实证明,有一种方法可以将多个库融合到一个单一的“胖子”中。一。 该实用程序称为lipo,您可以使用它:

      lipo -create "path_to_lib_1" "path_to_lib2" -output "path_to_desired_name_of_the_merged_library"
      

      所以:在iOS下,与索菲亚一起SIP作为一个同时执行32位和64位的单一库... Heewhhh ...

      ..... aaaaaaaa我们还没有完成......!

      问题:尝试执行任何操作(例如,REGISTER)会立即导致503 DNS错误发生 原因:Sofia在 etc / resolv.conf中搜索名称服务器列表
          显然,这是iOS,它要么不存在,要么它不在应用沙箱之外 解决方案:这是第二次,这个人,Antonis Tsakiridis,拯救我的屁股。恭敬的鞠躬。  首先,他谈到what he intends to do  其次,他展示了he has actually done

      然而,该解决方案暴露了一个新的......

      问题 _res_9_init - 未定义的架构符号(此处为armv7或arm64,具体取决于我为ARM_ARCH设置的内容),同时重新编译Sofia
      原因:我不知道。我只能从解决方案中推断,链接器需要被告知" resolv"库
      解决方案:在两个地方添加 -lresolv

      • LDFLAGS(在.bash_profile文件中)
      • 在Xcode"应用程序"项目(运用图书馆的那个);目标--->链接---> OtherLinkerFlags

      就像以前一样,虽然上面解决了它试图解决的问题,但它也将我们带到了下一个......

      问题:#IOS_BUILD(AT'第一个问题的解决方案的一部分)下的代码有条件执行没有发生。仍然得到503 DNS错误...
      原因:我无法弄明白我的生活在哪里实际定义。当然,在我自己的代码中的任何地方定义它可能没有任何效果,因为索菲亚应该是一个已编译的依赖;我们不会在预处理器中获得另一次机会来处理她的代码 解决方案:我将IOS_BUID #define替换为名为IOS_BUILD的环境变量,其值为...... well ... IOS_BUILD。我告诉Xcode关于它(我试图不使用"定义"以避免混淆) 产品--->方案---> EditScheme --->参数---> EnvironmentVariables
      在索非亚,我只是通过调用getenv()和strcmp()来替换#Ifdef IOS_BUILD。

      毕竟,看到...注册发生...
      此外,每次我将iPhone连接到另一个Wi-Fi时,都能正确检测到DNS设置,这要归功于Sofia的智能解决方案"。

答案 1 :(得分:2)

请注意,llvm-gcc已弃用;您应该使用clang代替:

% ls -l /usr/bin/llvm-gcc
lrwxr-xr-x  1 root  wheel  5 Nov  8  2013 /usr/bin/llvm-gcc@ -> clang

以下似乎对我有用:

export DEVROOT="$(xcrun --sdk iphoneos --show-sdk-platform-path)/Developer"
export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"

export CC="/usr/bin/clang"
export CXX="/usr/bin/clang++"

export LD="${DEVROOT}/usr/bin/ld"
export AR="${DEVROOT}/usr/bin/ar"
export AS="${DEVROOT}/usr/bin/as"
export NM="${DEVROOT}/usr/bin/nm"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export LDFLAGS="-L${SDKROOT}/usr/lib/"

export ARM_ARCH="armv7"  # or "armv6" and adjust the --host=[...] flag below
export CFLAGS="-arch ${ARM_ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -I${SDKROOT}/usr/include/"

export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"

配置:

./configure --host=armv7-apple-darwin

构建

make

验证

file `find . -name \*dylib`

输出:

./libsofia-sip-ua/.libs/libsofia-sip-ua.0.dylib:                                                       Mach-O dynamically linked shared library arm
./libsofia-sip-ua/.libs/libsofia-sip-ua.0.dylib.dSYM/Contents/Resources/DWARF/libsofia-sip-ua.0.dylib: Mach-O dSYM companion file arm
./libsofia-sip-ua/.libs/libsofia-sip-ua.dylib:                                                         Mach-O dynamically linked shared library arm

现金:

注意:

  • 我从另一个问题中删除了-miphoneos-version-min=[...]标志,因为我认为它与您的问题无关;如果您想将其添加回CFLAGS
  • ,由您决定