xcodemacoskernel-extension

Xcode: Link kernel framework to kernel extension?


I am attempting to write a kernel extension (kext) that uses some parts of the Kernel framework.

I added Kernel.framework to the list of Frameworks and Libraries in the target settings.

However, when I try to build my kext and link against it, Xcode refuses to do this and claims to not be able to find the framework, even though it had shown up in the list of available frameworks.

Am I doing this wrong? Is it not possible to use this framework even for kexts?

Edit: I am aware of the user space alternatives to kexts but these don't fulfill my needs.


Solution

  • The Kernel.framework is a header-only "framework". Kext linking is fundamentally different from user space executable linking, as there's no dyld. You don't need to link against any libraries at build time, but you must specify the KPIs to link against in the Info.plist file's OSBundleLibraries dictionary.

    You can generate a draft of this dictionary using the following command:

    kextlibs -xml -c path/to/your.kext
    

    If using any unsupported KPIs, you'll also want to specify -unsupported. If it's complaining about symbols not being found, adding the -undef-symbols option will help with debugging.