ar和libtool合并.a静态库
优质
小牛编辑
121浏览
2023-12-01
.a静态库合并
静态库是.o
文件的合集, 静态库合并就是将静态库的.o
合并, 可以实现的工具
ar
, 静态库的查看、拆分、合并libtool
,xcode
提供的静态库操作工具
以libtool
演示.a
静态库合并
一、准备
在
staticLib
文件夹里准备好两个.a
静态库目录结构
. ├── libAFNetworking.a └── libSDWebImage.a
二、合并
执行命令
libtool \ -static \ -o \ libMerge.a \ libAFNetworking.a \ libSDWebImage.a
参数说明
libMerge.a
是合并后生成静态库的名称libAFNetworking.a
和libSDWebImage.a
是将要被合并的两个静态库
生成最终静态库
. ├── libAFNetworking.a ├── libMerge.a └── libSDWebImage.a
利用
ar
来验证下静态库文件是否包含两个静态库的.o
文件ar -t /Users/shenyj/Documents/CodeForTest/staticLibMerge/staticLib/libMerge.a
输出结果
❯ ar -t /Users/shenyj/Documents/CodeForTest/staticLibMerge/staticLib/libMerge.a __.SYMDEF AFHTTPSessionManager.o AFNetworking-dummy.o AFNetworkReachabilityManager.o AFSecurityPolicy.o AFURLRequestSerialization.o AFURLResponseSerialization.o AFURLSessionManager.o NSBezierPath+SDRoundedCorners.o NSButton+WebCache.o NSData+ImageContentType.o NSImage+Compatibility.o SDAnimatedImage.o SDAnimatedImagePlayer.o SDAnimatedImageRep.o SDAnimatedImageView+WebCache.o SDAnimatedImageView.o SDAssociatedObject.o SDAsyncBlockOperation.o SDDeviceHelper.o SDDiskCache.o SDDisplayLink.o SDFileAttributeHelper.o SDGraphicsImageRenderer.o SDImageAPNGCoder.o SDImageAssetManager.o SDImageAWebPCoder.o SDImageCache.o SDImageCacheConfig.o SDImageCacheDefine.o SDImageCachesManager.o SDImageCachesManagerOperation.o SDImageCoder.o SDImageCoderHelper.o SDImageCodersManager.o SDImageFrame.o SDImageGIFCoder.o SDImageGraphics.o SDImageHEICCoder.o SDImageIOAnimatedCoder.o SDImageIOCoder.o SDImageLoader.o SDImageLoadersManager.o SDImageTransformer.o SDInternalMacros.o SDMemoryCache.o SDWeakProxy.o SDWebImage-dummy.o SDWebImageCacheKeyFilter.o SDWebImageCacheSerializer.o SDWebImageCompat.o SDWebImageDefine.o SDWebImageDownloader.o SDWebImageDownloaderConfig.o SDWebImageDownloaderDecryptor.o SDWebImageDownloaderOperation.o SDWebImageDownloaderRequestModifier.o SDWebImageDownloaderResponseModifier.o SDWebImageError.o SDWebImageIndicator.o SDWebImageManager.o SDWebImageOperation.o SDWebImageOptionsProcessor.o SDWebImagePrefetcher.o SDWebImageTransition.o UIButton+WebCache.o UIColor+SDHexString.o UIImage+ExtendedCacheData.o UIImage+ForceDecode.o UIImage+GIF.o UIImage+MemoryCacheCost.o UIImage+Metadata.o UIImage+MultiFormat.o UIImage+Transform.o UIImageView+HighlightedWebCache.o UIImageView+WebCache.o UIView+WebCache.o UIView+WebCacheOperation.o
以ar
演示.a
静态库合并
准备两个
.a
静态库:libAFNetworking.a
和libSDWebImage.a
. ├── libAFNetworking.a └── libSDWebImage.a
先将
.a
展开成.o
文件, 利用x
参数展开
AFNetworking
ar x /Users/shenyj/Documents/CodeForTest/lib/staticLibMerge/staticLib/libAFNetworking.a
展开
SDWebImage
ar x /Users/shenyj/Documents/CodeForTest/lib/staticLibMerge/staticLib/libSDWebImage.a
利用
ar
合并ar -rc libMerge.a *.o
生成新的
.a
静态库:libMerge.a
验证下合并是否成功
ar -t /Users/shenyj/Documents/CodeForTest/lib/staticLibMerge/staticLib/libMerge.a
会显示两个静态库的全部
.o
文件