苹果Mach-O链接器(id)警告:为MacOSX构build,但链接到为iOS构build的dylib

从过去xCode 4的某个时刻开始抱怨链接器问题:

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

我已经检查了一切,但仍然没有任何可疑的configuration,它编译和运行。 我唯一看到的是CoreGraphics.framework之前的双斜杠,为什么我不知道。 尝试删除并再次添加库“build设阶段”,没有帮助。

有时,通过查看所使用的命令行的构build日志来debuggingXcode问题会更容易。

如果从命令行构build,如果不指定-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) 

检查您的主要目标和testing目标的框架searchpath。

我有很多垃圾。

在XCode 4中编写了旧的项目,并开始在XCode 5中使用unit testing。

这是我必须让testing项目运行的最低要求

 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有硬编码path的坏习惯

 /Users/gbxc/Documents/my_project 

应该

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

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

最好的方法来检查什么是正确的是创build一个新的单个视图项目运行testing好。

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

如果您正在使用Carthage并编译Mac应用程序,请search项目的Framework Search Paths您可能会发现诸如$(PROJECT_DIR)/Carthage/Build/iOS

删除,解决了我的问题。

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