Home > OS >  Error "fatal error: 'sys/sysmacros.h' file not found"
Error "fatal error: 'sys/sysmacros.h' file not found"

Time:11-02

I have a compilation error on macOS v11 (Big Sur) with the standard Clang compiler (version 13.0.0).

I am trying to include the sys/sysmacros.h to use the makedev() function which surprisingly is mentioned on the Apple developer website and should be compatible with macOS 15.5 .

Including sys/types.h also gives me an error, however sys/stat.h works. Sadly it still doesn't give me the makedev(), major() and minor() functions that I need.

The Linux manual page of makedev states there were some changes in the glibc library, but as far as I know, macOS does not use the glibc library.

There should be a simple way of installing glibc on macOS using Homebrew (brew) as described here, but I get the same error as was mentioned in this question. So apparently currently there is no proper way of doing it and then I am not sure if this will solve my problem.

Is there a solution to this?

CodePudding user response:

The macro makedev is defined in sys/types.h. Just add #include <sys/types.h> into your files. sys/types.h is a header file of Kernel.framework. You should set it in the Clang invocation, like clang -framework Kernel ....

You can also define these macros as they are defined in sys/types.h:

#define major(x)        ((int32_t)(((u_int32_t)(x) >> 24) & 0xff))
#define minor(x)        ((int32_t)((x) & 0xffffff))
#define makedev(x, y)    ((dev_t)(((x) << 24) | (y)))
  • Related