10

我正在努力让我的图书馆像 CocoaPod 一样工作,如果有任何帮助可以为我指明正确的方向,我将不胜感激。

我以前从未制作过Pod,而且我觉得我已经做好了一切.h准备工作...... ,一个静态库,我的库使用。.m.swift.a

我在 Xcode 中的项目设置为将我的 Objective-C 库编译成一个.a库。如果我在 Xcode 中编译它,它会毫无问题地生成这个文件,但是,当我尝试对 podspec 进行 lint 处理时,我得到的链接器错误似乎与我试图链接到的静态库有关。

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 给出了链接器错误:

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 工作呢?

该库可以在 Github上找到。

4

2 回答 2

6

看起来您需要与 libiconv 链接。添加:

s.libraries = 'iconv'

在您的吊舱中将带您到达那里。

我已经在 Github 中向您发送了一个带有修复程序的拉取请求。

于 2015-08-23T06:02:57.193 回答
-5

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

但是,如果您支持 iOS8+,那么我建议您将Carthage视为附加/替代依赖管理器。您不会遇到您所描述的问题类型。我提出这个建议只是因为我过去使用过 CocoaPods 并且对它的工作方式感到沮丧。所以我一直在将我的项目切换到 Carthage,因为我发现它比 CocoaPods 处理起来要简单得多,并且不涉及任何 Ruby 黑客(没有 pod 规范)或踩踏你的项目文件。但是,它基于使用框架(因此是 iOS8+ 要求)而不是静态库,因此它是否适合您取决于您​​要实现的目标。

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

于 2015-08-17T00:29:34.467 回答