libarchive静态库
# 说明
基于libarchive.a + podspec
# 编译.a静态文件
- 下载代码 https://github.com/libarchive/libarchive/releases (opens new window)
- 修改
cat/CMakeLists.txt
,tar/CMakeLists.txt
,cpio/CMakeLists.txt
,unzip/CMakeLists.txt
,注释掉以下内容
# INSTALL(TARGETS bsdtar RUNTIME DESTINATION bin)
# INSTALL_MAN(${bsdtar_MANS})
- 生成Xcode代码项目文件
# 进入项目文件夹
# 结果输出到_builds文件夹
cmake -S. -B_builds -GXcode -DCMAKE_SYSTEM_NAME=iOS
- 打开
_builds
文件下的libarchive.xcodeproj
项目 - target选择
archive_static
,并修改为release
模式 - 开始编译,在
Products
文件夹获取libarchive.a
文件 - 从libarchive文件夹获取两个头文件
archive.h
和archive_entry.h
# 创建podspec
- 创建
pod lib create libarchive
,输出如下
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Quick / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
- 复制文件到
libarchive/Classes
文件夹
# tree libarchive
libarchive
├── Assets
└── Classes
├── include
│ ├── archive.h
│ └── archive_entry.h
└── lib
└── libarchive.a
- 修改
libarchive.podspec
文件
添加以下内容
s.static_framework = true
s.vendored_libraries = 'libarchive/Classes/lib/*a'
s.libraries = 'bz2','iconv','z'
修改后内容如下
Pod::Spec.new do |s|
s.name = 'libarchive'
s.version = '3.7.7'
s.summary = 'A short description of libarchive.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://github.com/Maktub/libarchive'ß
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Maktub' => '[email protected]' }
s.source = { :git => 'https://github.com/xxxxx/libarchive.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '15.0'
s.source_files = 'libarchive/Classes/**/*'
s.static_framework = true
s.vendored_libraries = 'libarchive/Classes/lib/*a'
s.libraries = 'bz2','iconv','z'
end
# 编译后libarchive.framework
,目录如下
libarchive.framework
├── Headers
│ ├── archive.h
│ ├── archive_entry.h
│ └── libarchive-umbrella.h
├── Info.plist
├── Modules
│ └── module.modulemap # swift项目使用的关键文件
└── libarchive
# 参考
上次更新: 2025/03/22, 03:52:10