[solved] Error: undefined reference to `major'

I am trying to build a fork of htop with added functionality for Raspberry Pi. Unfortunately, I get the following error:

OpenWrt-libtool: link: ccache_cc -pedantic -Wall -Wextra -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"/etc\" -I./linux -rdynamic -march=armv8-a+crc+simd -mtune=cortex-a72 -ftree-vectorize -O2 -pipe -fomit-frame-pointer -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/build_dir/target-aarch64_cortex-a72_musl/htop-2018-01-14-d87d5c01=htop-2018-01-14-d87d5c01 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z -Wl,now -Wl,-z -Wl,relro -znow -zrelro -o htop htop-AvailableMetersPanel.o htop-CategoriesPanel.o htop-CheckItem.o htop-ClockMeter.o htop-ColorsPanel.o htop-ColumnsPanel.o htop-CPUMeter.o htop-CRT.o htop-MainPanel.o htop-DisplayOptionsPanel.o htop-FunctionBar.o htop-Hashtable.o htop-Header.o htop-htop.o htop-ListItem.o htop-LoadAverageMeter.o htop-MemoryMeter.o htop-Meter.o htop-MetersPanel.o htop-Object.o htop-Panel.o htop-BatteryMeter.o htop-Process.o htop-ProcessList.o htop-RichString.o htop-ScreenManager.o htop-Settings.o htop-SignalsPanel.o htop-StringUtils.o htop-SwapMeter.o htop-TasksMeter.o htop-UptimeMeter.o htop-TraceScreen.o htop-UsersTable.o htop-Vector.o htop-AvailableColumnsPanel.o htop-AffinityPanel.o htop-HostnameMeter.o htop-OpenFilesScreen.o htop-Affinity.o htop-IncSet.o htop-Action.o htop-EnvScreen.o htop-InfoScreen.o htop-XAlloc.o linux/htop-Platform.o linux/htop-IOPriorityPanel.o linux/htop-IOPriority.o linux/htop-LinuxProcess.o linux/htop-LinuxProcessList.o linux/htop-LinuxCRT.o linux/htop-Battery.o linux/htop-CPUTempMeter.o linux/htop-CPUFreqMeter.o  -L/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/usr/lib -L/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/lib -lncurses -ltinfo -lm
/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/8.4.0/../../../../aarch64-openwrt-linux-musl/bin/ld: htop-Process.o: in function `Process_writeField':
Process.c:(.text+0xb28): undefined reference to `major'
/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/staging_dir/toolchain-aarch64_cortex-a72_gcc-8.4.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/8.4.0/../../../../aarch64-openwrt-linux-musl/bin/ld: Process.c:(.text+0xb34): undefined reference to `minor'
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:733: htop] Error 1
make[4]: Leaving directory '/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/build_dir/target-aarch64_cortex-a72_musl/htop-2018-01-14-d87d5c01'
make[3]: *** [Makefile:536: all] Error 2
make[3]: Leaving directory '/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/build_dir/target-aarch64_cortex-a72_musl/htop-2018-01-14-d87d5c01'
make[2]: *** [Makefile:58: /home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/build_dir/target-aarch64_cortex-a72_musl/htop-2018-01-14-d87d5c01/.built] Error 2
make[2]: Leaving directory '/home/alex/alex-openwrt/feeds/htop'
time: package/feeds/alexpackage/htop/compile#49.47#16.75#66.60
    ERROR: package/feeds/alexpackage/htop failed to build.
make[1]: *** [package/Makefile:114: package/feeds/alexpackage/htop/compile] Error 1
make[1]: Leaving directory '/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64'
make: *** [/home/alex/openwrt-sdk-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-aarch64/include/toplevel.mk:223: package/htop/compile] Error 2

Here is the makefile that I have developed based on the original makefile for htop.

#
# Copyright (C) 2007-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=htop

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/wbenny/htop.git
PKG_SOURCE_DATE:=2018-01-14
PKG_SOURCE_VERSION:=d87d5c01230565b7dbe7259d76c0b6152eb69688
PKG_HASH:=c951097e06994ef7cafc3d4dc7d7644a830003905abfb9dd1d5128204df95f4e

PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=COPYING

PKG_FIXUP:=autoreconf
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk

define Package/htop
	SECTION:=alextools
	CATEGORY:=Alex Addon Tools
	SUBMENU:=Administration
	TITLE:=Interactive processes viewer RPi mod
	DEPENDS:=+libncurses
	URL:=http://htop.sourceforge.net/
	MAINTAINER:=Alex
endef

define Package/htop/description
	Htop is an ncursed-based process viewer similar to top, but
	it allows to scroll the list vertically and horizontally to
	see all processes and their full command lines. RPi mod.
endef

CONFIGURE_ARGS += \
	--disable-unicode \
	--disable-hwloc

CONFIGURE_VARS += \
	ac_cv_file__proc_stat=yes \
	ac_cv_file__proc_meminfo=yes \

define Package/htop/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(PKG_NAME) $(1)/usr/bin/
endef

$(eval $(call BuildPackage,htop))

I have red in a Gentoo forum that some users solved a similar problem with changes by including <sys/sysmacros.h>. I have set-up to patches accordingly:
Patch 1

--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -24,7 +24,7 @@ in the source distribution for its full
 #include <string.h>
 #include <time.h>
 #include <assert.h>
-#include <sys/types.h>
+#include <sys/sysmacros.h>
 #include <fcntl.h>
 
 /*{

Patch 2:

--- a/configure.ac
+++ b/configure.ac
@@ -59,7 +59,7 @@ AC_HEADER_STDC
 AC_CHECK_HEADERS([stdlib.h string.h strings.h sys/param.h sys/time.h unistd.h],[:],[
   missing_headers="$missing_headers $ac_header"
 ])
-AC_CHECK_HEADERS([execinfo.h],[:],[:])
+AC_CHECK_HEADERS([execinfo.h sys/sysmacros.h],[:],[:])
 
 # Checks for typedefs, structures, and compiler characteristics.
 # ----------------------------------------------------------------------

Any idea how to resolve the issue?

Maybe have a look at how htop.dev solved the issue in their code.

That solved it! Thank you very much. If anyone runs into the same problem, here is the patch that I did based on the above input.

--- a/Process.c
+++ b/Process.c
@@ -29,6 +29,13 @@ in the source distribution for its full
 #include <assert.h>
 #include <math.h>
 
+#ifdef MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#elif defined(MAJOR_IN_SYSMACROS) || \
+   (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
+#include <sys/sysmacros.h>
+#endif
+
 #ifdef __ANDROID__
 #define SYS_ioprio_get __NR_ioprio_get
 #define SYS_ioprio_set __NR_ioprio_set
--- a/configure.ac
+++ b/configure.ac
@@ -61,6 +61,16 @@ AC_CHECK_HEADERS([stdlib.h string.h stri
 ])
 AC_CHECK_HEADERS([execinfo.h],[:],[:])
 
+AC_HEADER_MAJOR
+dnl glibc 2.25 deprecates 'major' and 'minor' in <sys/types.h> and requires to
+dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
+dnl been updated in Autoconf 2.69, so use a workaround:
+m4_version_prereq([2.70], [],
+[if test $ac_cv_header_sys_mkdev_h = no; then
+   AC_CHECK_HEADER(sys/sysmacros.h, [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
+      [Define to 1 if `major', `minor', and `makedev' are declared in <sys/sysmacros.h>.])])
+fi])
+
 # Checks for typedefs, structures, and compiler characteristics.
 # ----------------------------------------------------------------------
 AC_HEADER_STDBOOL
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -26,6 +26,12 @@ in the source distribution for its full
 #include <assert.h>
 #include <sys/types.h>
 #include <fcntl.h>
+#ifdef MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#elif defined(MAJOR_IN_SYSMACROS) || \
+   (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
+#include <sys/sysmacros.h>
+#endif
 
 /*{

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.