Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create dynamic library for PJSIP

We've a script that will compile PJSIP to a fat static library. But we would like to create a dynamic library so that it can be used within swift only projects.

Update 9 sept 2016:

When compiling PJSIP with the "--enable-shared" option, most of the lib's are build correctly. However, some libs are compile for the wrong architecture, in this case x86_64 instead of arm64

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

Whereas these are correct:

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

When we start building:

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

al complete correctly but

+ make

generates these warnings:

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

and a lot of warnings looking like this:

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

and:

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

What could be the reason that some lib are compiled for the correct architecture and some are not? How would I be able to fix this?

For background information, the environment variables as printed by 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: calling ./aconfigure with env vars:

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

Initial process:

The process we have so far is:

  1. create a fat static library for 1 architecture with the PJSIP bash scripts.
  2. extract everything into seperate o files with lipo and ar
  3. trying to make a dynamic library with libtool.

But we have issues with linking to other frameworks (for as far we can tell). Is this the case or do we do something else wrong?

This is step 3 in detail:

We have all the files of 1 architecture in 1 folder. Then we run this libtool command:

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

Start of our output after running the command:

    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
like image 890
Bob Voorneveld Avatar asked Aug 26 '16 09:08

Bob Voorneveld


1 Answers

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.

like image 110
clemens Avatar answered Oct 17 '22 11:10

clemens