如何创建包含静态库的 pod?

How to create a pod that includes static libraries?

我正在努力让我的图书馆像 CocoaPod 一样工作,如果能为我指明正确的方向,我将不胜感激。

我以前从未制作过 Pod,我觉得我已经把一切都做好了,这可以工作......如果它是一个简单的 pod,只是未编译 .h/.m/.swift 文件,但是,我的库包含一个已编译的 .a 文件,我的库使用的静态库。

我在 Xcode 中的项目设置为将我的 Objective-C 库编译成 .a 库。如果我在 Xcode 中编译它,它会毫无问题地生成这个文件,但是,当我尝试检查 podspec 时,我会得到 linker 错误,这些错误似乎与我的静态库有关我正在尝试 link 到。

SQLConnect.podspec

#
# Be sure to run `pod lib lint NAME.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
  s.name                = "SQLConnect"
  s.version             = "1.2.0"
  s.summary             = "Connects apps to SQL Server"
  s.description         = <<-DESC
                            A library for connecting Objective-C & Swift apps to SQL Server
                        DESC
  s.homepage            = "http://importblogkit.com"
  s.license             = 'MIT'
  s.authors             = { "Nick Griffith" => "nhgrif@gmail.com" }
  s.social_media_url    = 'https://twitter.com/importBlogKit'
  s.source              = { :git => "https://github.com/nhgrif/SQLConnect.git", :tag => s.version.to_s }

  s.platform                = :ios, '8.0'
  s.ios.deployment_target   = '8.0'
  s.requires_arc            = true
  s.public_header_files     = 'SQLConnect/*.h', 'SQLConnect/SQLSettings/*.h', 'SQLConnect/SQLControllers/*.h', 'SQLConnect/SQLConnection/*.h'
  s.source_files            = 'SQLConnect/**/*.{h,m}'
  s.preserve_paths          = 'SQLConnect/**/*.*'
  s.vendored_libraries      = 'SQLConnect/FreeTDS/libfreetds.a'
  s.xcconfig                = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/SQLConnect/**" }
end

我也尝试过其他方法,比如将库设为子规范,但似乎没有任何效果。

尽管在 Xcode 中编译正常,但 linter 给出 linker 错误:

The following build commands failed:
    Ld /var/folders/yj/h_f7h7ws3zzfd__f847qys3m0000gn/T/CocoaPods/Lint/build/Pods.build/Release-iphonesimulator/Pods-SQLConnect.build/Objects-normal/i386/SQLConnect normal i386
    Ld /var/folders/yj/h_f7h7ws3zzfd__f847qys3m0000gn/T/CocoaPods/Lint/build/Pods.build/Release-iphonesimulator/Pods-SQLConnect.build/Objects-normal/x86_64/SQLConnect normal x86_64
(2 failures)
 -> SQLConnect (1.2.0)
    - ERROR | [iOS] Returned an unsuccessful exit code.
    - NOTE  |  clang: error: linker command failed with exit code 1 (use -v to see invocation)

Analyzed 1 podspec.

[!] The spec did not pass validation.

向上滚动输出,我可以找到这些错误:

Undefined symbols for architecture i386:
  "_iconv", referenced from:
      _tds_iconv_init in libfreetds.a(iconv.o)
      _tds_iconv in libfreetds.a(iconv.o)
      _skip_one_input_sequence in libfreetds.a(iconv.o)
      _tds_iconv_fread in libfreetds.a(iconv.o)
     (maybe you meant: _tds_iconv_close, _tds_iconv_get , _tds_iconv , _tds_iconv_alloc , _tds_iconv_free , _tds_iconv_from_collate , _tds_iconv_open , _tds_iconv_fread )
  "_iconv_close", referenced from:
      _tds_iconv_init in libfreetds.a(iconv.o)
      _tds_iconv in libfreetds.a(iconv.o)
      _skip_one_input_sequence in libfreetds.a(iconv.o)
      __iconv_close in libfreetds.a(iconv.o)
      _tds_set_iconv_name in libfreetds.a(iconv.o)
     (maybe you meant: _tds_iconv_close)
  "_iconv_open", referenced from:
      _tds_iconv_init in libfreetds.a(iconv.o)
      _tds_iconv_info_init in libfreetds.a(iconv.o)
      _tds_iconv in libfreetds.a(iconv.o)
      _skip_one_input_sequence in libfreetds.a(iconv.o)
      _tds_set_iconv_name in libfreetds.a(iconv.o)
     (maybe you meant: _tds_iconv_open)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
      _tds_iconv_open in libfreetds.a(iconv.o)
      _tds_iconv in libfreetds.a(iconv.o)
      _tds_iconv_fread in libfreetds.a(iconv.o)
     (maybe you meant: _tds_iconv_close, _tds_iconv_get , _tds_iconv , _tds_iconv_alloc , _tds_iconv_free , _tds_iconv_from_collate , _tds_iconv_open , _tds_iconv_fread )
  "_iconv_close", referenced from:
      _tds_iconv_open in libfreetds.a(iconv.o)
      _tds_iconv_info_close in libfreetds.a(iconv.o)
      _tds_iconv in libfreetds.a(iconv.o)
      _tds_set_iconv_name in libfreetds.a(iconv.o)
     (maybe you meant: _tds_iconv_close)
  "_iconv_open", referenced from:
      _tds_iconv_open in libfreetds.a(iconv.o)
      _tds_iconv_info_init in libfreetds.a(iconv.o)
      _tds_iconv in libfreetds.a(iconv.o)
      _tds_set_iconv_name in libfreetds.a(iconv.o)
     (maybe you meant: _tds_iconv_open)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这似乎表明项目有问题...但我可以毫无问题地将它编译成 .a。我还通过将原始源文件或生成的 .a 文件(我的 libSQLConnect.a,而不仅仅是 libFreeTDS.a)拖到 iOS 项目中来使用这个库。

那么我该如何使它作为一个 pod 工作呢?

图书馆可以找到here on Github

我无法帮助您解决 CocoaPod 问题。

但如果您支持 iOS8+,那么我建议您将 Carthage 视为 additional/alternative 依赖项管理器。您不会遇到您所描述的问题类型。我之所以这么建议,是因为我过去曾使用过 CocoaPods,但对它的工作方式感到失望。所以我一直在将我的项目切换到 Carthage,因为我发现它比 CocoaPods 更容易处理,并且不涉及任何 Ruby 黑客攻击(没有 pod 规范)或遍历你的项目文件。但是,它基于使用框架(因此 iOS8+ 要求)而不是静态库,因此它是否适合您取决于您​​要实现的目标。

PS。不,我不是 Carthage 的维护者。我只是碰巧喜欢它:-)

看来您需要 link 使用 libiconv。添加:

s.libraries = 'iconv'

在你的 pod 中将带你到那里。

我已在 Github 中向您发送了包含修复程序的拉取请求。