【问题标题】:Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOSApple Mach-O 链接器(id)警告:为 MacOSX 构建,但链接到为 iOS 构建的 dylib
【发布时间】:2011-11-02 16:05:00
【问题描述】:

从过去 xCode 4 开始抱怨链接器问题:

ld:警告:为 MacOSX 构建,但链接到为构建的 dylib IOS: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks//CoreGraphics.framework/CoreGraphics

我已经检查了所有内容,但配置中仍然没有任何可疑之处,它可以编译并运行。 我唯一看到的是CoreGraphics.framework之前的双斜杠,为什么我不知道。尝试在“构建阶段”上删除并再次添加库,但没有帮助。

【问题讨论】:

    标签: ios xcode linker dylib mach-o


    【解决方案1】:

    有时通过查看其正在使用的命令行的构建日志来调试 Xcode 问题会更容易。

    如果你是从命令行构建的,如果你不指定 -miphoneos-version-min=

    This compiles:
    (where conftest.c just contains int main() {})
    /Applications/Xcode5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -miphoneos-version-min=6.0 conftest.c
    
    And this gives the error:
    /Applications/Xcode5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk  conftest.c
    ld: building for MacOSX, but linking against dylib built for iOS Simulator file '/Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/usr/lib/libSystem.dylib' for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    【讨论】:

    • 在 Xcode 项目中添加这些 thnigs 的位置?我正在从 Xcode 编译,而不是从命令行编译...这是我得到的错误 ld: building for iOS Simulator,但链接到为 MacOSX 文件构建的 dylib '/usr/lib/libSystem.B。 dylib' for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) Others Linker Flat 中有一个 libSystem.B.dylib 条目部分..但删除它并不能解决问题。
    【解决方案2】:

    检查主目标和测试目标的框架搜索路径。

    我有很多废话。

    有一个用 XCode 4 编写的旧项目,刚刚开始在 XCode 5 中使用单元测试。

    这是让我的测试项目运行的最低要求

    Project Navigator > click on project at top >
    Targets > Build Settings > Framework Search Paths
    

    TARGET:my_project
    $(inherited)
    "$(SRCROOT)"
    "$(SRCROOT)/my_project"
    
    TEST:my_projectTests
    "$(SDKROOT)/Developer/Library/Frameworks"    <<XCTest.framework is here
    "$(DEVELOPER_LIBRARY_DIR)/Frameworks"
    "$(SRCROOT)/.."
    "$(SRCROOT)"                             << Documents/my_project
    "$(SRCROOT)/my_project"                  << Documents/my_project/my_project
    
    where directory structure is
    Documents/my_project
        my_project.xcodeproj
        /my_project
    

    注意:如果将框架拖入 XCode。 XCode 5 有硬编码路径的坏习惯

    /Users/gbxc/Documents/my_project
    

    应该是

    "$(SRCROOT)"                             << Documents/my_project
    "$(SRCROOT)/my_project"                  << Documents/my_project/my_project
    

    所以如果你移动你的项目可能会遇到问题

    检查是否正确的最佳方法是创建一个新的单视图项目,该项目可以正常运行测试。

    Run the Test action
    By default it fails but at least testing is running
    then compare the  Framework Search Paths.
    

    【讨论】:

    • 更改 *Tests 目标中的搜索框架顺序为我修复了它。确保 $(inherited) 不在“$(SDKROOT)/Developer/Library/Frameworks”之前。
    【解决方案3】:

    如果您使用 Carthage 并编译 Mac 应用程序,请搜索您项目的 Framework Search Paths,您可能会找到类似 $(PROJECT_DIR)/Carthage/Build/iOS 的内容。

    删除解决了我的问题。

    【讨论】:

      【解决方案4】:

      此问题是由于在 Xcode 中包含错误的框架版本。该项目是为 Mac OS X 构建的,但它使用 iOS 版本的框架。

      【讨论】:

        猜你喜欢
        • 2013-09-11
        • 1970-01-01
        • 2011-12-06
        • 1970-01-01
        • 1970-01-01
        • 2014-05-30
        • 2017-12-20
        • 1970-01-01
        • 2012-04-26
        相关资源
        最近更新 更多