Reputation: 470
By gcc -v
I know that gcc searches in these paths:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
I write:
#include <CoreFoundation/CoreFoundation.h>
int main() {
return 0;
}
It gives no error messages. But with the following, gcc cannot find the header.
#include <CoreFoundation.framework/Headers/CoreFoundation.h>
int main() {
return 0;
}
I know that gcc finds the header CoreFoundation.h in /System/Library/Frameworks
. And the path of the header is /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h
.
My question is: why #include <CoreFoundation/CoreFoundation.h>
is OK? Why not CoreFoundation.framework/Headers/CoreFoundation.h
(it gives error messages)? I think it should be CoreFoundation.framework/Headers/CoreFoundation.h
, as the full path of the header is /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h
, and the inlcude path is /System/Library/Frameworks
.
Thanks in advance.
The following may have something to do with this problem.
I compile a file that include 'CoreServices/CoreServices.h'.
did not find header 'CoreServices.h' in framework 'CoreServices' (loaded from '/System/Library/Frameworks')
Then I use gcc -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/
, because I know the header's path is /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h
. But it still doesn't work. Why?
Upvotes: 1
Views: 1477
Reputation: 38991
Two lines in the gcc -v
output is a hint about special directories that are handled not like include directories.
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
Apple's gcc for Darwing architecture has special extensions for finding include files from framworks. You can read about the Darwin Options
Especially look at -Fdir option. It allows to specify other framework dirs additional to the listed above. This option describes how gcc looks for header files in a framework:
A framework directory is a directory with frameworks in it. A framework is a directory with a
Headers
and/orPrivateHeaders
directory contained directly in it that ends in.framework
. The name of a framework is the name of this directory excluding the.framework
. Headers associated with the framework are found in one of those two directories, withHeaders
being searched first. A subframework is a framework directory that is in a framework’sFrameworks
directory. Includes of subframework headers can only appear in a header of a framework that contains the subframework, or in a sibling subframework header. Two subframeworks are siblings if they occur in the same framework. A subframework should not have the same name as a framework; a warning is issued if this is violated. Currently a subframework cannot have subframeworks; in the future, the mechanism may be extended to support this. The standard frameworks can be found in/System/Library/Frameworks
and/Library/Frameworks
. An example include looks like#include <Framework/header.h>
, whereFramework
denotes the name of the framework andheader.h
is found in thePrivateHeaders
orHeaders
directory.
Upvotes: 4