Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS

为君一笑 提交于 2019-11-26 23:06:39

问题


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.


回答1:


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)



回答2:


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.



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/7173626/apple-mach-o-linker-id-warning-building-for-macosx-but-linking-against-dyli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!