我们有一个脚本将PJSIP编译为一个庞大的静态库。但是我们想创建一个动态库,这样它就可以在swift项目中使用。
更新9 sept 2016:
当使用"——enable-shared"选项编译PJSIP时,大多数库的是正确构建的。然而,在这种情况下,有些库是为错误的体系结构编译的X86_64代替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
然而这些是正确的:
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: calling ./configure 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
初始过程:
到目前为止我们的进程是:
- 使用PJSIP bash脚本为1架构创建一个胖的静态库。
- 用lipo和ar将所有内容提取到单独的文件中
- 试图用libtool创建一个动态库。
但是我们在链接到其他框架时遇到了问题(据我们所知)。是这样还是我们做错了什么?
这是步骤3的细节:
我们在一个文件夹中有一个架构的所有文件。然后运行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
共享库在运行时加载。因此,您必须为您的应用程序提供库,并自己用dlopen
(3)加载它,因为您不能将它安装到系统库路径中。你还必须共同设计你的库。
但是这没有意义:
- 当您从多个应用程序加载共享库时,它们是有意义的。在iOS上,这只能是你的应用和它的扩展。你应该使用动态框架。
- 苹果可能会拒绝你的二进制文件,如果他们检测到共享库,他们会指向共享框架。
将库包含到共享框架中应该很容易。只需将静态库添加到链接框架和共享框架中的库。确保静态库被编译为定位独立的代码,这应该是默认的。