<Cocoa/Cocoa.h> location
Asked Answered
U

4

5

I am new to Mac OS X development. In XCode/Cocoa developers environment each Objective-C projects starts with
#import <Cocoa/Cocoa.h>
It works fine but I am puzzled with Cocoa.h file location. There is no Cocoa.h file in Cocoa folder on my file system. I tried to "find / Cocoa/Cocoa.h" and "locate Cocoa/Cocoa.h" nothing was found.
Can anybody give me a hint on how and where compiler finds Cocoa.h header in above #import statement.

Thanks, Recovering Microsoft Addict

Umpteen answered 23/11, 2010 at 19:14 Comment(0)
K
7

Cocoa/ refers to the /System/Library/Frameworks/Cocoa.framework/Headers/ folder. If you check your project, under "Frameworks" you'll see your included frameworks and cntrl-click to 'reveal in finder' will help.

Kipp answered 23/11, 2010 at 19:18 Comment(8)
You can also put your insertion point between the <> and press ⇧⌘D (Open Quickly), then ⌘-click the new window's title bar to see where the file is or go to one of its ancestor directories.Catiline
Thank you Peter and Stephen for your help. With your expertise I found my Cocoa.h in /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Cocoa.framework/Headers. It still remains a mystery how XCode maps the path to Cocoa/ to resolve import statement.Umpteen
@pcmaniac: Cocoa is the name of the framework (i.e. it occurs before ".framework") and the compiler knows that headers go in the framework's Headers directory. That's how it maps the path.Argil
@Chuck: Naming convention sounds like very weak form of mapping. There must be a plist or something. Just try to drop some iPhoneOS related framework (e.g UIKit) to MacOSX dev or System library. Compiler by itself wont find UIKit/UIKit.hUmpteen
@Umpteen you have to include the "Base SDK" for the libs you're using under the Build Settings for the target. If you change it to 10.5 from 10.6, it points to a completely different Cocoa.framework. And Naming Conventions is the name of the game with Cocoa. Camel is pretty much standard for things like @properties and the like.Kipp
@pcmaniac, if you want to include an iOS framework you just need to point the Framework Search Paths to where you want it to look.Kipp
Thanks Stephen, you are right. But there a is mapping process running by XCode IDE to let compiler find header files - see answer below.Umpteen
@pcmaniac, but XCode is primarily a GUI for gcc. anything that works with gcc will work in XCode, so you don't have to go through mapping or anything else to include stuff.Kipp
U
3

I finally found an answer in Xcode Build Setting Reference section Header-Map Build Settings.
Turned out XCode behind the scene "magically" mapping headers to paths storing info in .hmap files to pass the .hmap files to gcc (compiler).
Environment var HEADERMAP_INCLUDES_FRAMEWORK_ENTRIES_FOR_ALL_PRODUCT_TYPES must be set to use Cocoa/Cocoa.h syntax in #import statements.
And no, Finder does not show .hmap files - use Terminal commands to get them.

Umpteen answered 25/11, 2010 at 6:45 Comment(3)
Correction: You can navigate to .hmap files in Finder but Spotlight does not find them.Umpteen
To locate .hmap files from XCode IDE:Umpteen
1. Open Build Results 2. Cmnd-Click and select Open Latest Results as Transcript Text File 3. In Build log file find ".hmap" or scroll to gcc calls and look for -I parameterUmpteen
E
0

Spotlight seems to find any header file I have looked for on the system as well.

Enoch answered 24/11, 2010 at 4:8 Comment(0)
H
0

2024 update

Things have changed quite a bit in the last years. Especially the headers no longer ship with the default installation, e.g. when Xcode is not installed.

First, you need to install Xcode and the command line tools then find the sdk-path like this:

xcrun --sdk macosx --show-sdk-path

Here it evaluates to:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk

from that point you cd to System/Library/Frameworks/Cocoa.framework/Headers resulting in the whole path as /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/Cocoa.framework/Headers

Hak answered 11/7, 2024 at 17:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.