Glibc 2.26 porting notes/sysmacros.h

From Gentoo Wiki
Jump to: navigation, search

Description

To support upcoming c++ standards glibc plans to remove <sys/sysmacros.h> from glibc's <sys/types.h>. See the announcement.

<sys/sysmacros.h> defines the following macros:

  • major()
  • minor()
  • makedev()

Build breakage usually looks like that:

  bdev/lxclvm.c: In function 'lvm_detect':
  bdev/lxclvm.c:140:4: error: implicit declaration of function 'major' [-Werror=implicit-function-declaration]
    major(statbuf.st_rdev), minor(statbuf.st_rdev));
    ^~~~~
  bdev/lxclvm.c:140:28: error: implicit declaration of function 'minor' [-Werror=implicit-function-declaration]
    major(statbuf.st_rdev), minor(statbuf.st_rdev));
                            ^~~~~

How to fix

autoconf-based systems

Note: <sys/sysmacros.h> is a non-standard header. Most portable fix across various libcs is to use [AC_HEADER_MAJOR] macro.

# somewhere in configure.ac:
# lookup major()/minor()/makedev()
AC_HEADER_MAJOR
/* somewhere in C code */
#ifdef MAJOR_IN_MKDEV
#    include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#    include <sys/sysmacros.h>
#endif

Links