missing include in kern/ directory

Hi. I'm using the Kernel framework and I'm having an issue with it: in my project I include from the framework the header Kernel/kern/thread.h. When I try to compile my source code XCode says that he is unable to find an header included by the Kernel framework: kern/kern_types.h. Actually I don't understand how this is possible, but I went to check in /usr/include and effectively inside kern/ (wich is where the incude does reference) are missing a lot of file. How can I fix this problem? Thanks to everyone.


Snapshot from /usr/include/kern, where all kern/ files are missing.


Replies

Modern version of Xcode don’t use headers from the system, that is, in

/usr/include/
. Rather, Xcode picks up headers from the SDK built in to Xcode. For example, when you include
<netdb.h>
in a Mac project you actually get
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/netdb.h
(assuming Xcode is installed in the standard place).

This is further complicated by the fact that kernel development doesn’t use the standard headers at all. Rather, all kernel headers are packaged inside the

Kernel
[pseudo-]framework. So, for example,
<kern/kern_types.h>
actually resolves to
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/kern/kern_types.h
.

If you’re building kernel code and Xcode is not finding

<kern/kern_types.h>
, the most likely problem is that Xcode doesn’t know that you’re building kernel code. The necessary flags get automatically configured when you create a kernel target, so my best guess is that you’re trying to build kernel code in a non-kernel target.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
  • @eskimo Having this issue myself... XCode 13.1 command line tools installed... I'm trying to build a project that just has a makefile and a .c file... what flags need tto be added to the build command line for this to work?

  • Okay, looks like I needed the following...

    KERNELDIR := $(shell xcrun --sdk macosx --show-sdk-path)/System/Library/Frameworks/Kernel.framework/Headers

    Then... --include-directory=$(KERNELDIR) in the build flags...

Add a Comment

For anyone that comes across this later... I declared a KERNELIR in my Makefile.

KERNELDIR := $(shell xcrun --sdk macosx --show-sdk-path)/System/Library/Frameworks/Kernel.framework/Headers

And used that with --include-directory=$(KERNELDIR) in my Makefile