Apple Mach-O链接器(id)警告:为MacOSX构建,但是针对为iOS构建的dylib进行链接

Igo*_*gor 25 xcode linker mach-o dylib ios

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

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

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

Jam*_*ore 5

有时,通过查看正在使用的命令行的构建日志来调试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)
Run Code Online (Sandbox Code Playgroud)

  • 在Xcode项目中添加这些文件的位置?我正在从Xcode编译,而不是从命令行编译......这是我得到的错误**ld:为iOS模拟器构建,但是针对为MacOSX文件构建的dylib链接'/usr/lib/libSystem.B.dylib '对于体系结构i386 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)**_Others Linker Flat_部分中有一个libSystem.B.dylib条目但是删除它无法解决问题. (4认同)

bri*_*ear 5

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

我有很多废话。

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

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

Project Navigator > click on project at top >
Targets > Build Settings > Framework Search Paths
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)

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

/Users/gbxc/Documents/my_project
Run Code Online (Sandbox Code Playgroud)

应该

"$(SRCROOT)"                             << Documents/my_project
"$(SRCROOT)/my_project"                  << Documents/my_project/my_project
Run Code Online (Sandbox Code Playgroud)

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

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

Run the Test action
By default it fails but at least testing is running
then compare the  Framework Search Paths.
Run Code Online (Sandbox Code Playgroud)


Rap*_*tor -3

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