1

我有这个项目,其中包含两个目标,一个用于 iOS,一个用于 OSX。这是 Podfile 的样子。

# Pods

xcodeproj 'ipolypus.xcodeproj'

pod 'BlocksKit'
pod 'Reachability'
pod 'MKStoreKit'

# Objective C
pod 'libextobjc'
pod 'LinqToObjectiveC'

target :ipolypus, :exclusive => false do
    platform :ios, '5.1.1'
    pod 'CocoaLumberjack'
    pod 'EGOTableViewPullRefresh'
    pod 'SVProgressHUD'
    pod 'FlurrySDK'

    # AdMob SDK and AdMob mediation adapter
    pod 'AdMob'
    pod 'AdMobMediationAdapterIAd'    
end

target :ipolypusTests, :exclusive => true do
    pod 'CocoaLumberjack'
end

target :'ipolypus-osx', :exclusive => false do
    platform :osx
    pod 'CocoaLumberjack'
end

运行后,pod install我可以看到两个 Pod 库链接到第一个目标 ( ipolypus)。

libPods.alibPods-ipolypus.a

如果我尝试立即构建项目,我会收到奇怪的链接错误,例如缺少 FlurrySDK 符号。

要修复它,我必须从库列表中删除libPods.a并与目标链接,再次运行,然后手动删除第一个目标,然后它将构建和链接。libPods-ipolypus.apod installlibPods.a

我做那个的方式一定有问题Podfile。我查了相关的帖子,没有发现类似的问题。

更新

这是链接错误

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_Flurry", referenced from:
      objc-class-ref in IOSAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

完成上述步骤后,我将成功构建直到下一个pod installpod update.

我还应该提到,该项目有很长一段时间是单一目标,然后我添加了 OSX 目标并为此进行了修改Podfile,这就是问题开始的时候。但是我尝试删除Podfile.lock并擦除Pods文件夹,仍然出现问题。

而且我遇到了另一种类型的错误,链接器失败,因为已经定义了相同的符号,但我再也看不到那个了。

4

1 回答 1

2

I got to the cause of "double-linking" problem. It's caused by the structure of the Podfile, as expected. Since I wanted to have some common pods available both for OSX and iOS targets, I put them all in the beginning.

xcodeproj 'ipolypus.xcodeproj'

pod 'BlocksKit'
pod 'Reachability'
pod 'MKStoreKit'

# Objective C
pod 'libextobjc'
pod 'LinqToObjectiveC'

These common pods will be in libPods.a library, also, CocoaPods can't stand the fact that some pods library is not linked against a target, so it will link libPods.a against default project target, in my example it's ipolypus.

Then there's libPods-ipolypus.a generated for ipolypus iOS target. Since this target is not exclusive, things like FlurrySDK will be included into both libPods.a and libPods-ipolypus.a, resulting into duplicated symbols while linking.

After trying to figure out the proper way to use exclusive/non-exclusive target configs, I ended up with separate list of pods for each target. Might be a bit longer than I would want, but does the job as expected.

# Pods

xcodeproj 'ipolypus.xcodeproj'

target :ios, :exclusive => true do
    platform :ios, '6.0'
    link_with 'ipolypus'

    # shared
    pod 'CocoaLumberjack'
    pod 'Reachability'
    pod 'MKStoreKit'
    pod 'LinqToObjectiveC'
    # pod 'EGOTableViewPullRefresh'

    # platform
    pod 'SVProgressHUD'
    pod 'FlurrySDK'

    # AdMob SDK and AdMob mediation adapter
    pod 'Google-Mobile-Ads-SDK'
    pod 'AdMobMediationAdapterIAd'
end

target :iosTests, :exclusive => true do
    platform :ios, '6.0'
    link_with 'ipolypusTests'
    pod 'OCMock'
end

target :osx, :exclusive => false do
    platform :osx, '10.7'
    link_with 'ipolypus-osx'

    # shared
    pod 'CocoaLumberjack'
    pod 'Reachability'
    pod 'LinqToObjectiveC'
end

target :osxTests, :exclusive => true do
    platform :osx, '10.7'
    link_with 'ipolypus-osxTests'
    pod 'OCMock'
end
于 2014-01-28T23:04:28.140 回答