我们有一个脚本可以将PJSIP编译成胖的静态库。但我们想创建一个动态库,以便它可以在swift only项目中使用。
2016年9月9日更新:
使用" - enable-shared"编译PJSIP时选项,大部分的lib 正确构建。 但是,在这种情况下,有些lib是针对错误的体系结构进行编译的 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
为某些lib编译正确的原因可能是什么原因 建筑有些不是吗?我怎么能解决这个问题?
有关背景信息,打印的环境变量 配置-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:使用env vars调用./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
初始流程:
我们到目前为止的过程是:
但是我们在链接到其他框架方面存在问题(我们可以告诉他们)。是这种情况还是我们做错了什么?
这是第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
答案 0 :(得分:1)
在运行时加载共享库。因此,您必须为库提供应用程序,并自行加载dlopen
(3),因为您无法将其安装到系统库路径中。您还必须对您的图书馆进行编码。
但这没有意义:
将libs包含在共享框架中应该很容易。只需将静态库添加到共享框架中的 Linked Frameworks and Libraries 即可。确保编译静态库以定位独立代码,这应该是默认代码。