I’ve never done this myself but I suspect it’s feasible. The tricky thing here is that KEXT targets build with special flags (for example,
-mkernel, but that’s just one of many) that get the code to build in kernel mode, and you need to build your static library the same way. If you don’t, you’ll end up trying to load user-space-built code into the kernel, which is going to end badly.
My trick for this sort of thing is to create a dummy project in Xcode, build it, and then look at the build transcript to see how Xcode invoked the compiler and linker. In this case you’d need to do that twice, once for a KEXT and another time for a static library. Once you’ve isolated the KEXT-relevant flags in the former, you can copy them over to the latter.
Honestly, if I were you, I’d just include your utilities library as source as part of your main KEXT target. Building C code is pretty darned fast, and Xcode is pretty good about only rebuilding code that’s changed, so a static library will only speed up the initial build, and I don’t think that’s worth the extra complexity.
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
After some pratice, the answer is yes. But we need to take care to build the static lib with kernel stuff such as kernel framework and header files which is something tricky a little bit for new hand...