Search code examples
c++xcodemacosiokitkernel-extension

Xcode Build failed because of Semantic Issues in libkern.h


I'm trying to compile a sound card driver from GitHub (https://github.com/i3roly/CMI8788) in Xcode but I'm getting two semantic issues that I simply don't understand. I'm really confused because the issues are not in the code itself but in the macOS framework. It's about the file libkern.h

I tried compiling it on Xcode 9 because I thought, that it may be a issue with Xcode 10. same result.

It's about that part of libkern.h:

extern int  ffs(int);
extern int  ffsll(unsigned long long);
extern int  fls(int);
extern int  flsll(unsigned long long);
extern u_int32_t    random(void);
extern int  scanc(u_int, u_char *, const u_char *, int);
extern int  skpc(int, int, char *);
extern long strtol(const char*, char **, int);
extern u_long   strtoul(const char *, char **, int);
extern quad_t   strtoq(const char *, char **, int);
extern u_quad_t strtouq(const char *, char **, int);
extern char *strsep(char **, const char *);
extern void *memchr(const void *, int, size_t);
extern void url_decode(char *str);

This is the result in the log file:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Headers/IOKit/IOLib.h:44:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Headers/IOKit/system.h:57:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Headers/libkern/libkern.h:145:12: error: conflicting types for 'ffsll'
extern int      ffsll(unsigned long long);
                ^
In file included from /Users/jakob/Documents/CMI8788/CMI8788/XonarHDAVAudioEngine.cpp:47:
In file included from /usr/include/string.h:180:
/usr/include/strings.h:86:6: note: previous declaration is here
int      ffsll(long long) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
         ^
In file included from /Users/jakob/Documents/CMI8788/CMI8788/XonarHDAVAudioEngine.cpp:49:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Headers/IOKit/IOLib.h:44:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Headers/IOKit/system.h:57:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Headers/libkern/libkern.h:147:12: error: conflicting types for 'flsll'
extern int      flsll(unsigned long long);

I hope somebody can tell me what's going on. Thank you!


Solution

  • The problem originates in the following line:

    #import </usr/include/string.h>
    

    Don't include files with an absolute path. The Kernel.framework has its own version of string.h which you can just include via #include <string.h>. User-space header files may cause build errors or more subtle problems when building a kext. Don't use them.

    The line above it,

    #import </usr/include/libkern/OSAtomic.h>
    

    should probably also be using a relative path: <libkern/OSAtomic.h>

    Side note:

    Using #import (Objective-C) may or may not work for C & C++ headers; sometimes they will behave differently on subsequent #include directives, so if you have any further problems, switch to #include.