简体   繁体   中英

How is a blank, new Cocoa app project linking with the system frameworks?

I've created a blank new Cocoa Application project. Inside it has just

#import <Cocoa/Cocoa.h>

in main.m and AppDelegate.h (plus the necessary boilerplate). The " Link Binary with Libraries " list is empty under Build Phases, as is the "Linked Frameworks and Libraries" list under General.

Yet, the app links and runs just fine . I wonder why ?

The reason I'm asking is because in a different project, similarly not explicitly linked to any system frameworks, and with the necessary #import <Cocoa/Cocoa.h> the compilation succeeds, but linking fails unless I link with the Cocoa framework. Would like to know the exact reason.


Here's the Link step from the blank new project that mysteriously works:

Ld /Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Products/Debug/Dummy.app/Contents/MacOS/Dummy normal x86_64
    cd /Users/me/Desktop/Dummy
    export MACOSX_DEPLOYMENT_TARGET=10.11
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch x86_64
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
-L/Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Products/Debug
-F/Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Products/Debug
-filelist /Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Intermediates/Dummy.build/Debug/Dummy.build/Objects-normal/x86_64/Dummy.LinkFileList
-Xlinker
-rpath
-Xlinker @executable_path/../Frameworks
-mmacosx-version-min=10.11
-Xlinker
-object_path_lto
-Xlinker /Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Intermediates/Dummy.build/Debug/Dummy.build/Objects-normal/x86_64/Dummy_lto.o
-Xlinker
-export_dynamic
-Xlinker
-no_deduplicate
-fobjc-arc
-fobjc-link-runtime
-Xlinker
-dependency_info
-Xlinker /Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Intermediates/Dummy.build/Debug/Dummy.build/Objects-normal/x86_64/Dummy_dependency_info.dat
-o /Users/me/Library/Developer/Xcode/DerivedData/Dummy-denigwgxslheroapywoedahwvhkx/Build/Products/Debug/Dummy.app/Contents/MacOS/Dummy

When you create a new project, Xcode will set the Link Frameworks Automatically flag to YES. Then the clang linking flag will be set to CLANG_MODULES_AUTOLINK = YES . With this option, clang will linking the framework for you automatically.

When you set this flag to NO 在此处输入图片说明

Then the linking process will be failed without adding the library into Link Binary with Libraries list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM