xcode Apple Mach-O 链接器 (id) 警告:为 MacOSX 构建,但链接为为 iOS 构建的 dylib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7173626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS
提问by Igor
Starting from some point in the past xCode 4 in complaining about linker problems:
从过去 xCode 4 抱怨链接器问题的某个时间点开始:
ld: warning: building for MacOSX, but linking against dylib built for iOS: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks//CoreGraphics.framework/CoreGraphics
ld:警告:为 MacOSX 构建,但链接为为 iOS 构建的 dylib:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks//CoreGraphics.framework/CoreGraphics
I have checked everything but still nothing suspicious in the config and it compiles and runs. The only thing that I see it is double slashes before CoreGraphics.framework, why I do not know. Tried remove and add again library on "Build phases" that did not help.
我已经检查了所有内容,但在配置中仍然没有任何可疑之处,并且它可以编译并运行。我唯一看到的是 CoreGraphics.framework 之前的双斜线,我不知道为什么。尝试在“构建阶段”中删除并再次添加库,但没有帮助。
回答by James Moore
Sometimes it's easier to debug Xcode problems by looking at the build log for the command lines it's using.
有时,通过查看正在使用的命令行的构建日志来调试 Xcode 问题会更容易。
If you're building from the command line, you can get that message if you don't specify -miphoneos-version-min=
如果您是从命令行构建的,并且未指定-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)
回答by brian.clear
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.
有用 XCode 4 编写的旧项目,刚刚开始在 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
注意:如果您将框架拖入 XCode。XCode 5 有硬编码路径的坏习惯
/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.
回答by olivaresF
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
.
如果您正在使用 Carthage 并编译 Mac 应用程序,请搜索您的项目,Framework Search Paths
您可能会找到类似$(PROJECT_DIR)/Carthage/Build/iOS
.
Removing that fixed my issue.
删除它解决了我的问题。
回答by Raptor
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.
此问题是由于 Xcode 中包含错误的框架版本。该项目是为 Mac OS X 构建的,但它使用 iOS 版本的框架。