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

26

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

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

我已经检查了所有内容,但配置中没有可疑的地方,而且它也能编译和运行。我唯一看到的问题是在CoreGraphics.framework之前有双斜杠,我不知道为什么。尝试在“Build Phases”中删除并重新添加库,但没有帮助。

4个回答

6
有时候,查看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)

5
这些东西应该在Xcode项目的哪里添加?我是从Xcode编译的,而不是从命令行...这是我收到的错误信息:ld: 构建iOS Simulator,但链接到用于MacOSX文件'/usr/lib/libSystem.B.dylib'的dylib,体系结构为i386 clang:错误:链接器命令失败,退出代码1(使用-v查看调用)在“其他链接器平面”部分中有一个“libSystem.B.dylib”的条目..但是删除它并不能解决这个问题。 - Ans

5

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

我的搜索路径里有很多无用的东西。

我曾使用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"之前。 - Marius

0
如果您正在使用Carthage并编译Mac应用程序,请搜索您项目的Framework Search Paths,您可能会发现类似于$(PROJECT_DIR)/Carthage/Build/iOS的内容。
删除这个路径可以解决我的问题。

-3

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接