17

PJSIP をファットな静的ライブラリにコンパイルするスクリプトがあります。しかし、swift のみのプロジェクト内で使用できるように、動的ライブラリを作成したいと考えています。

2016 年 9 月 9 日更新:

「--enable-shared」オプションを指定して PJSIP をコンパイルすると、ほとんどのライブラリが正しくビルドされます。ただし、一部のライブラリは間違ったアーキテクチャ用にコンパイルされています。この場合は、arm64 ではなく x86_64 です。

libg7221codec.dylib is architecture: x86_64
libgsmcodec.dylib is architecture: x86_64
libilbccodec.dylib is architecture: x86_64
libresample.dylib is architecture: x86_64
libyuv.dylib is architecture: x86_64

これらは正しいですが:

libpjsip.dylib is architecture: arm64
libpjsua.dylib is architecture: arm64
libpjsua2.dylib is architecture: arm64

構築を開始するとき:

+ ./configure-iphone --enable-shared
+ make dep
+ make clean

すべて正しく完了しますが、

+ make

次の警告が生成されます。

ld: warning: -undefined dynamic_lookup is deprecated on iOS
ld: warning: -flat_namespace is deprecated on iOS

そして、次のような多くの警告が表示されます:

ld: warning: ignoring file
output/libilbccodec-arm64-apple-darwin_ios/iLBC_decode.o, file was built
for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x0C 0x00 0x00 0x01 0x00
0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being
linked (x86_64): output/libilbccodec-arm64-apple-darwin_ios/iLBC_decode.o
ld: warning: ignoring file
output/libg7221codec-arm64-apple-darwin_ios/common/common.o, file was built
for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x0C 0x00 0x00 0x01 0x00
0x00 0x00 0x00 0x01 0x00 0x00 0x00 ) which is not the architecture being
linked (x86_64): output/libg7221codec-arm64-apple-darwin_ios/common/common.o

と:

ld: warning: ignoring file /pjsip/src/third_party/lib/libg7221codec.dylib,
file was built for x86_64 which is not the architecture being linked
(arm64): /pjsip/src/third_party/lib/libg7221codec.dylib

一部のライブラリが正しいアーキテクチャ用にコンパイルされ、一部がコンパイルされていない理由は何ですか? どうすればこれを修正できますか?

背景情報として、configure-iphone によって出力される環境変数:

configure-iphone: DEVPATH is not specified, using
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
configure-iphone: IPHONESDK is not specified, choosing iPhoneOS9.3.sdk
configure-iphone: CC is not specified, choosing
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/../../../Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
configure-iphone: CXX is not specified, using
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/../../../Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

configure-iphone: 環境変数で ./aconfigure を呼び出す:

CC =
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/../../../Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 CXX =
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/../../../Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
 SDKPATH =
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk
 CFLAGS = -miphoneos-version-min=9.0 -DPJ_SDK_NAME="\"iPhoneOS9.3.sdk\""
-arch arm64 -isysroot
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk
 LDFLAGS = -O2 -arch arm64 -isysroot
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk
-framework AudioToolbox -framework Foundation
 AR =
/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/../../../Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
-static -o
 RANLIB = echo ranlib
 ARCH = arm64

初期プロセス:

これまでのプロセスは次のとおりです。

  1. PJSIP bash スクリプトを使用して、1 つのアーキテクチャ用のファット スタティック ライブラリを作成します。
  2. lipo と ar を使用して、すべてを個別の o ファイルに抽出します
  3. libtool で動的ライブラリを作成しようとしています。

しかし、他のフレームワークへのリンクには問題があります (私たちが知る限り)。これは事実ですか、それとも他に何か間違ったことをしていますか?

これはステップ 3 の詳細です。

1 つのフォルダに 1 つのアーキテクチャのすべてのファイルがあります。次に、次の libtool コマンドを実行します。

libtool -dynamic *.o -o pjsip.dylib -framework AudioToolbox -framework Foundation -framework AVFoundation -framework CoreFoundation -lSystem -ios_version_min 9.0

コマンド実行後の出力の開始:

    ld: warning: -force_cpusubtype_ALL will become unsupported for ARM architectures
Undefined symbols for architecture armv7s:
  "_AVAudioSessionCategoryPlayAndRecord", referenced from:
      _ca_factory_init in coreaudio_dev.o
  "_AVAudioSessionModeVoiceChat", referenced from:
      _ca_factory_init in coreaudio_dev.o
  "_AudioComponentFindNext", referenced from:
      _ca_factory_init in coreaudio_dev.o
      _ca_stream_set_cap in coreaudio_dev.o
  "_AudioComponentGetDescription", referenced from:
      _ca_stream_get_cap in coreaudio_dev.o
  "_AudioComponentInstanceDispose", referenced from:
      _ca_stream_destroy in coreaudio_dev.o
  "_AudioComponentInstanceNew", referenced from:
      _create_audio_unit in coreaudio_dev.o
  "_AudioConverterDispose", referenced from:
      _ca_stream_destroy in coreaudio_dev.o
      _ilbc_dealloc_codec in ilbc.o
  "_AudioConverterFillComplexBuffer", referenced from:
      _resample_callback in coreaudio_dev.o
      _ilbc_codec_encode in ilbc.o
      _ilbc_codec_decode in ilbc.o
      _ilbc_codec_recover in ilbc.o
  "_AudioConverterNew", referenced from:
      _ilbc_codec_open in ilbc.o
  "_AudioConverterReset", referenced from:
      _ca_stream_start in coreaudio_dev.o
  "_AudioFormatGetProperty", referenced from:
      _ilbc_codec_open in ilbc.o
  "_AudioOutputUnitStart", referenced from:
      _ca_stream_start in coreaudio_dev.o
  "_AudioOutputUnitStop", referenced from:
      _ca_stream_start in coreaudio_dev.o
      _ca_stream_stop in coreaudio_dev.o
  "_AudioUnitInitialize", referenced from:
      _create_audio_unit in coreaudio_dev.o
  "_AudioUnitRender", referenced from:
      _resample_callback in coreaudio_dev.o
      _input_callback in coreaudio_dev.o
  "_AudioUnitSetProperty", referenced from:
      _create_audio_unit in coreaudio_dev.o
  "_AudioUnitUninitialize", referenced from:
      _ca_stream_destroy in coreaudio_dev.o
  "_CFArrayGetCount", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFArrayGetValueAtIndex", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFDataGetBytePtr", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFHostCreateWithName", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFHostGetAddressing", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFHostStartInfoResolution", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFReadStreamClose", referenced from:
      _activesock_destroy_iphone_os_stream in activesock.o
  "_CFReadStreamOpen", referenced from:
      _activesock_create_iphone_os_stream in activesock.o
  "_CFReadStreamSetProperty", referenced from:
      _activesock_create_iphone_os_stream in activesock.o
  "_CFRelease", referenced from:
      _activesock_destroy_iphone_os_stream in activesock.o
      _pj_getaddrinfo in addr_resolv_sock.o
  "_CFStreamCreatePairWithSocket", referenced from:
      _activesock_create_iphone_os_stream in activesock.o
  "_CFStringCreateWithCStringNoCopy", referenced from:
      _pj_getaddrinfo in addr_resolv_sock.o
  "_Gsm_LPC_Analysis", referenced from:
      _Gsm_Coder in code.o
  "_Gsm_Preprocess", referenced from:
      _Gsm_Coder in code.o
  "_OBJC_CLASS_$_AVAudioSession", referenced from:
      objc-class-ref in coreaudio_dev.o
  "_OBJC_CLASS_$_UIDevice", referenced from:
      objc-class-ref in os_info_iphone.o
  "__DefaultRuneLocale", referenced from:
      __Z8__istypeim in siptypes.o
4

1 に答える 1

1

Shared libraries are loaded at runtime. Thus you must provide the library with your application, and load it with dlopen(3) by yourself, because you cannot install it into the system library paths. You must also codesign your library.

But this doesn't make sense:

  1. Shared libraries make sense, when you load them from multiple applications. On iOS this can only be your application and its extensions. You should use a dynamic framework instead.
  2. Apple will probably reject your binary, if they detect the shared library, and they will point to shared frameworks.

Including the libs into a shared framework should be easy. Just add the static libraries to Linked Frameworks and Libraries from the shared framework. Ensure that the static libs are compiled to position independent code, which should be the default.

于 2016-11-25T06:41:09.703 に答える