Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS

后端 未结 4 1941
Happy的楠姐
Happy的楠姐 2020-12-05 23:28

Starting from some point in the past xCode 4 in complaining about linker problems:

ld: warning: building for MacOSX, but linking against dylib built f

相关标签:
4条回答
  • 2020-12-05 23:57

    This issue is due to include a wrong framework version in Xcode. The project is built for Mac OS X, but it uses iOS version's framework.

    0 讨论(0)
  • 2020-12-06 00:03

    Check your Framework Search Paths for your Main target and your test Target.

    I had a lot of crap in mine.

    had old project written in XCode 4 and just started to use Unit Tests in XCode 5.

    Here's the minimum I have to get my test project to run

    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
    

    Note: If you drag a framework into XCode. XCode 5 has bad habit of hardcoding the path

    /Users/gbxc/Documents/my_project
    

    should be

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

    so if you moved your project might get problems

    Best way to check whats correct is to create a new single view project that runs tests ok.

    Run the Test action
    By default it fails but at least testing is running
    then compare the  Framework Search Paths.
    
    0 讨论(0)
  • 2020-12-06 00:16

    If you're using Carthage and compiling a Mac app, search on your project's Framework Search Paths you might find something like $(PROJECT_DIR)/Carthage/Build/iOS.

    Removing that fixed my issue.

    0 讨论(0)
  • 2020-12-06 00:18

    Sometimes it's easier to debug Xcode problems by looking at the build log for the command lines it's using.

    If you're building from the command line, you can get that message if you don't specify -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)
    
    0 讨论(0)
提交回复
热议问题