Building on MacOS and get "use of undeclared identifier" error

Build Device: MacBook 2021 with M1 Pro, MacOS 13.0.1
Target Device: NanoPi R2s with RK3328 SoC

At first I built it with multi-thread, most of the package builds well but uboot failed

Then I tried to build uboot only with single thread, and get lots of use of undeclared identifier error
image|675x500

Full Output
make package/boot/uboot-rockchip/compile -j1 V=s
make[2]: Entering directory '/Volumes/openwrt/openwrt/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/Volumes/openwrt/openwrt/scripts/config'
make[1]: Entering directory '/Volumes/openwrt/openwrt'
make[2]: Entering directory '/Volumes/openwrt/openwrt/package/libs/toolchain'
echo "libc" >> /Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/pkginfo/toolchain.default.install
echo "libgcc" >> /Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/pkginfo/toolchain.default.install
echo "libstdcpp" >> /Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/pkginfo/toolchain.default.install
echo "libpthread" >> /Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/pkginfo/toolchain.default.install
echo "librt" >> /Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/pkginfo/toolchain.default.install
make[2]: Leaving directory '/Volumes/openwrt/openwrt/package/libs/toolchain'
time: package/libs/toolchain/compile#0.16#0.13#0.35
make[2]: Entering directory '/Volumes/openwrt/openwrt/package/boot/arm-trusted-firmware-rockchip'
Makefile:49: WARNING: skipping arm-trusted-firmware-rockchip -- package has no install section
make[2]: Leaving directory '/Volumes/openwrt/openwrt/package/boot/arm-trusted-firmware-rockchip'
time: package/boot/arm-trusted-firmware-rockchip/compile#0.21#0.12#0.43
make[2]: Entering directory '/Volumes/openwrt/openwrt/package/boot/uboot-rockchip'
rm -f /Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r2s-rk3328/u-boot-2021.07/.built
touch /Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r2s-rk3328/u-boot-2021.07/.built_check
make  -C /Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r2s-rk3328/u-boot-2021.07 CROSS_COMPILE=aarch64-openwrt-linux-musl- DTC="/Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/linux-rockchip_armv8/linux-5.15.88/scripts/dtc/dtc" HOSTCC="gcc" HOSTCFLAGS="-O2 -I/Volumes/openwrt/openwrt/staging_dir/host/include -I/Volumes/openwrt/openwrt/staging_dir/hostpkg/include -I/Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/host/include -I/Volumes/openwrt/openwrt/staging_dir/host/include -I/Volumes/openwrt/openwrt/staging_dir/hostpkg/include -I/Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/host/include -std=gnu11" HOSTLDFLAGS="-L/Volumes/openwrt/openwrt/staging_dir/host/lib -L/Volumes/openwrt/openwrt/staging_dir/hostpkg/lib -L/Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/host/lib" LOCALVERSION="-OpenWrt-r21859-116c73fd71" STAGING_PREFIX="/Volumes/openwrt/openwrt/staging_dir/host" PKG_CONFIG_PATH="/Volumes/openwrt/openwrt/staging_dir/host/lib/pkgconfig" PKG_CONFIG_LIBDIR="/Volumes/openwrt/openwrt/staging_dir/host/lib/pkgconfig" PKG_CONFIG_EXTRAARGS="--static" V='' BL31=/Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/image/rk3328_bl31.elf
make[3]: Entering directory '/Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r2s-rk3328/u-boot-2021.07'
===================== WARNING ======================
This board uses CONFIG_SPL_FIT_GENERATOR. Please migrate
to binman instead, to avoid the proliferation of
arch-specific scripts with no tests.
====================================================
  CFGCHK  u-boot.cfg
  WRAP    tools/lib/crc8.c
tools/Makefile:251: warning: pattern recipe did not update peer target 'tools/env/crc8.c'.
tools/Makefile:251: warning: pattern recipe did not update peer target 'tools/common/crc8.c'.
  HOSTCC  tools/lib/crc8.o
  HOSTLD  tools/gen_ethaddr_crc
ld: warning: directory not found for option '-L/Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/host/lib'
  WRAP    tools/lib/crc32.c
tools/Makefile:251: warning: pattern recipe did not update peer target 'tools/common/crc32.c'.
  HOSTCC  tools/lib/crc32.o
  HOSTLD  tools/mkenvimage
ld: warning: directory not found for option '-L/Volumes/openwrt/openwrt/staging_dir/target-aarch64_generic_musl/host/lib'
  HOSTCC  tools/aisimage.o
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:13:
include/linux/types.h:146:9: error: unknown type name '__u64'; did you mean '__s64'?
typedef __u64 __bitwise __le64;
        ^
/Volumes/openwrt/openwrt/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;
                                           ^
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:13:
include/linux/types.h:147:9: error: unknown type name '__u64'; did you mean '__s64'?
typedef __u64 __bitwise __be64;
        ^
/Volumes/openwrt/openwrt/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;
                                           ^
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:14:
include/linux/byteorder/swab.h:125:42: error: unknown type name '__u64'; did you mean '__s64'?
static __inline__ __attribute__((const)) __u64 __fswab64(__u64 x)
                                         ^
/Volumes/openwrt/openwrt/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;
                                           ^
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:14:
include/linux/byteorder/swab.h:125:58: error: unknown type name '__u64'; did you mean '__s64'?
static __inline__ __attribute__((const)) __u64 __fswab64(__u64 x)
                                                         ^
/Volumes/openwrt/openwrt/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;
                                           ^
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:14:
include/linux/byteorder/swab.h:130:12: error: use of undeclared identifier '__u64'
        return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h)));
                  ^
include/linux/byteorder/swab.h:130:42: error: use of undeclared identifier '__u64'
        return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h)));
                                                ^
include/linux/byteorder/swab.h:135:19: error: unknown type name '__u64'; did you mean '__s64'?
static __inline__ __u64 __swab64p(const __u64 *x)
                  ^
/Volumes/openwrt/openwrt/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;
                                           ^
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:14:
include/linux/byteorder/swab.h:135:41: error: unknown type name '__u64'; did you mean '__s64'?
static __inline__ __u64 __swab64p(const __u64 *x)
                                        ^
/Volumes/openwrt/openwrt/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;
                                           ^
In file included from tools/aisimage.c:9:
In file included from include/image.h:19:
In file included from ./arch/arm/include/asm/byteorder.h:29:
In file included from include/linux/byteorder/little_endian.h:14:
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
        return __arch__swab64p(x);
               ^
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:89:24: note: expanded from macro '__swab64'
(__builtin_constant_p((__u64)(x)) ? \
                       ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:32:4: note: expanded from macro '___swab64'
        ((__u64)( \
          ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:33:4: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
                 ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:33:13: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
                          ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:33:26: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
                                       ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:34:4: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
                 ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:34:13: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
                          ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:34:26: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
                                       ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:35:4: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
                 ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:35:13: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
                          ^
include/linux/byteorder/swab.h:137:9: error: use of undeclared identifier '__u64'
include/linux/byteorder/swab.h:62:30: note: expanded from macro '__arch__swab64p'
#  define __arch__swab64p(x) __swab64(*(x))
                             ^
include/linux/byteorder/swab.h:90:2: note: expanded from macro '__swab64'
 ___swab64((x)) : \
 ^
include/linux/byteorder/swab.h:35:26: note: expanded from macro '___swab64'
                (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
                                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[4]: *** [scripts/Makefile.host:112: tools/aisimage.o] Error 1
make[3]: *** [Makefile:1822: tools] Error 2
make[3]: Leaving directory '/Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r2s-rk3328/u-boot-2021.07'
make[2]: *** [Makefile:109: /Volumes/openwrt/openwrt/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r2s-rk3328/u-boot-2021.07/.built] Error 2
make[2]: Leaving directory '/Volumes/openwrt/openwrt/package/boot/uboot-rockchip'
time: package/boot/uboot-rockchip/nanopi-r2s-rk3328/compile#0.82#0.89#2.26
    ERROR: package/boot/uboot-rockchip failed to build (build variant: nanopi-r2s-rk3328).
make[1]: *** [package/Makefile:116: package/boot/uboot-rockchip/compile] Error 1
make[1]: Leaving directory '/Volumes/openwrt/openwrt'
make: *** [/Volumes/openwrt/openwrt/include/toplevel.mk:231: package/boot/uboot-rockchip/compile] Error 2

Thanks if anyone can help

Instead of building on raw macOS, fire up a Linux (Debian works fine) VM, and follow the Linux build guide. IIRC macOS is not a supported build host, not directly.

1 Like

MacOS should work, but for x86_64 devices. AFAIK ARM64 ones are largely untested.

Free oracle cloud FTW again :slight_smile:

1 Like

Yes I also had lots of errors with M1 Macs... also because "the GCC compiler is too newer" or something similiar, I ended by compiling my build on the oracle VM. Way better!

Do you use the Ampere A1 VM? This one is based on ARM too... Does it work well?

read the other thread ?

Some time ago, I successfully built openwrt on MacOS12, but now its MacOS13 :thinking:
I guess it's caused by Apple Clang, heres my gcc version

version info
gcc -v && llvm-gcc -v && clang -v
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Finally I successfully build it on a suck x86 Debian machine, and it took me 1.5 hours :smiling_face_with_tear:

Yes but it’s running on Oracle OS (CentOS), not macOS.

I haven’t digged into what’s the issue with macOS and the OpenWrt build environment, I just tried one time on an external SSD and I saw lots of weird errors due to the gcc compiler (too newer IIRC), then I switched to Oracle VM.

I build my images for the NanoHDs and the RPi4 in a macOS 13 on an M1 Pro. Just make sure you have all your GNU tools installed using brew, and that you export the right PATHs before firing up the build.

PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"
PATH="/opt/homebrew/opt/gnu-getopt/bin:$PATH"
PATH="/opt/homebrew/opt/gettext/bin:$PATH"
PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"
PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"
3 Likes

I created the env.sh following [OpenWrt Wiki] Build system setup macOS
And Im pretty sure that my PATH is correct

PATH
echo $PATH
/Volumes/openwrt/openwrt/staging_dir/toolchain-aarch64_generic_gcc-12.2.0_musl:/Volumes/openwrt/openwrt/staging_dir/host:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/coreutils/libexec/gnubin:/opt/homebrew/opt/gettext/bin:/opt/homebrew/opt/gnu-getopt/bin:/opt/homebrew/opt/make/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin

I do have same errors while building uboot-mvebu, but otherwise building on MacOS works, no need to set up Linux VM.

//EDIT:

This should help. The patch is already present for sunxi and mediatek U-boots even though it is hack, it works.

It seems that this is fixed by this commit: