您如何追溯导入框架的来源?

时间:2013-10-15 10:12:52

标签: ios objective-c xcode module linker

使用Xcode 4和iOS 6 SDK以便使用QuartzCore.framework中的类,您必须链接QuartzCore.framework和#import <QuartzCore/QuartzCore.h>。这很好,这是有道理的。我对世界的看法很满意:)

在带有iOS 7 SDK的Xcode 5中,QuartzCore标题似乎是自动导入的。使用CA类不会引发警告或链接器错误。

我的问题是:

鉴于这些标题显然是从某个地方导入并且链接了库,我如何跟踪导入源和链接框架?这更多只是为了我的好奇心,更多地了解这个过程,而不是解决一个特定的问题。

其他信息:

  • 模块已打开(默认情况下在Xcode 5中),但@import未在任何代码中使用。但是,将Enable Modules (C and Objective-C)Link Frameworks Automatically都切换为“No”似乎不需要#import of QuartzCore进行编译。
  • 关闭模块后,查看Product |执行操作|预处理显示预处理输出中的QuartzCore标头。这解释了为什么代码编译,而不是它来自何处。
  • otool在其输出中没有显示QuartzCore框架:

    $ otool -L Test 
    Test:
        /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
        /System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 2903.2.0)
        /System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1047.20.0)
        /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
        /usr/lib/libSystem.dylib (compatibility version 1.0.0, current version 111.0.0)
    

使用部分解决方案进行编辑

  • 我至少想出了#import的来源。通过iOS 7 UIKit标头检查,UISlider现在包含导入<QuartzCore/QuartzCore.h>,但在iOS 6中没有。神秘的解决了,但缺少链接器错误仍然很奇怪。

1 个答案:

答案 0 :(得分:2)

看起来它是由UIKit链接的,可能与LC_REEXPORT_DYLIB相关联。

有关此Twitter帖子的更多信息:https://twitter.com/daveverwer/status/390060215221354496

在UIKit.framework上运行otool表明它已链接。

$ otool -L UIKit 
UIKit:
    /System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 2380.17.0)
    /System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreVideo.framework/CoreVideo (compatibility version 1.2.0, current version 1.8.0)
    /System/Library/Frameworks/VideoToolbox.framework/VideoToolbox (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/MobileAsset.framework/MobileAsset (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/TelephonyUtilities.framework/TelephonyUtilities (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/WebBookmarks.framework/WebBookmarks (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/BackBoardServices.framework/BackBoardServices (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/XPCObjects.framework/XPCObjects (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 49.1.0)
    /System/Library/Frameworks/CoreImage.framework/CoreImage (compatibility version 1.0.0, current version 2.0.0)
    /System/Library/Frameworks/Security.framework/Security (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/DictionaryServices.framework/DictionaryServices (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 993.0.0)
    /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices (compatibility version 1.0.0, current version 14.0.0)
    /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation (compatibility version 150.0.0, current version 793.0.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
    /System/Library/Frameworks/ImageIO.framework/ImageIO (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/QuartzCore.framework/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
    /System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/PrivateFrameworks/AppSupport.framework/AppSupport (compatibility version 1.0.0, current version 29.0.0)
    /System/Library/Frameworks/CoreText.framework/CoreText (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices (compatibility version 1.0.0, current version 40.0.0)
    /usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 9.6.0)
    /System/Library/PrivateFrameworks/WebKit.framework/WebKit (compatibility version 1.0.0, current version 536.26.0)
    /System/Library/PrivateFrameworks/WebCore.framework/WebCore (compatibility version 1.0.0, current version 536.26.0)
    /System/Library/PrivateFrameworks/ProofReader.framework/ProofReader (compatibility version 1.0.0, current version 180.0.0)
    /System/Library/Frameworks/CFNetwork.framework/CFNetwork (compatibility version 1.0.0, current version 609.1.4)
    /usr/lib/libAccessibility.dylib (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Accelerate.framework/Accelerate (compatibility version 1.0.0, current version 4.0.0)
    /System/Library/PrivateFrameworks/PrintKit.framework/PrintKit (compatibility version 1.0.0, current version 109.2.0)
    /usr/lib/libMobileGestalt.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
    /usr/lib/libSystem.dylib (compatibility version 1.0.0, current version 125.0.0)