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

发布于 2024-12-01 15:39:02 字数 377 浏览 1 评论 0原文

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

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

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泛滥成性 2024-12-08 15:39:02

有时,通过查看其所使用的命令行的构建日志来调试 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)

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)
﹏半生如梦愿梦如真 2024-12-08 15:39:02

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

我的心里有很多废话。

有用 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.

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.
喜爱皱眉﹌ 2024-12-08 15:39:02

如果您使用 Carthage 并编译 Mac 应用程序,请搜索项目的框架搜索路径,您可能会找到类似 $(PROJECT_DIR)/Carthage/Build/iOS 的内容。

删除它解决了我的问题。

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.

姐不稀罕 2024-12-08 15:39:02

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文