NanoPi R1 - Mac OS 10.15.5 Build: unknown type name '__u64'; did you mean '__s64'?

I'm quite a n00b with complex build environments like OpenWrt, and I'm running into quite a few small issues building on Mac OS 10.15.5. I started building in an Ubuntu VM but found the interface is quite clunky, it looks a mess on my MacBook Pro's Retina screen lol, and it seems to have trouble interfacing with my Saitechi USB-C microSD reader, leaving a locked ghost volume mounted after ejecting each time and requiring a restart before it works, which is supposedly a well known Ubuntu "bug".

I'm trying to build a custom image with some UI tweaks for the NanoPi R1. I've followed the recommended build procedure for Mac OS (build on a disk image with case-sensitive HFS+, use homebrew versions of various GNU tools, use a script that sets path, etc.), and am using the tool from https://github.com/djpadz/openwrt-osx-build as well, and I've managed to get menuconfig to build (and have the NanoPi R1 as a target, for some reason when cloning the git on my Mac, this wasn't there, so I moved the buildroot from the Linux VM and ran make defclean and the R1 remained in the target list).

The build issue I'm stuck on now is:

  HOSTCC  tools/img2srec
  HOSTCC  tools/mkenvimage.o
  HOSTCC  tools/os_support.o
  WRAP    tools/lib/crc32.c
  HOSTCC  tools/lib/crc32.o
  HOSTLD  tools/mkenvimage
ld: warning: directory not found for option '-L/Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/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;
        ^
../../../../staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;

I tracked down the types.h referenced, and adding a Mac OS __u64 def from https://github.com/dropbox/goebpf/blob/master/bpf.h
but the types.h file is obviously being generated by some part of the process so any changes I make are overwritten.

Am I even approaching this the right way? Where would be the right place to include Mac OS specific stuff (as that unrelated, but good example, bpf.h file is doing)? Any particular reason these wouldn't just be included in OpenWrt? Perhaps doing so would just be uncovering an even bigger can of worms? Or, perhaps, they are included but since I moved this buildroot from my Linux VM, they're missing. In that case, what should I be doing to "clean" this buildroot but make sure I don't end up unable to select the NanoPi R1?

Should I try cloning the git again and just try to figure out why the NanoPi R1 doesn't show up in the menuconfig? I did update the feeds etc, and followed the same documentation and process as I did on my Linux VM to the best of my knowledge.

Thanks

Ok, so I managed to resolve this error by adding

#define __NR_bpf 515
typedef unsigned short __u16;  // NOLINT
typedef unsigned char __u8;
typedef unsigned int __u32;
typedef unsigned long long __u64;  // NOLINT
typedef __u64 __aligned_u64;
#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))

after line 16 in openwrt/staging_dir/host/include/asm/types.h

Unfortunately now I'm getting:

checking whether CONNECT_RESUME_ON_READ_WRITE is declared... no
configure: error: TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client
make[3]: *** [Makefile:266: /Volumes/OpenWrt/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/unbound-1.13.0/.configured_60214bb2b54800d4c3e2f823aed3f714] Error 1
make[3]: Leaving directory '/Volumes/OpenWrt/openwrt/feeds/packages/net/unbound'
time: package/feeds/packages/unbound/compile#14.52#7.33#34.36
    ERROR: package/feeds/packages/unbound failed to build.
make[2]: *** [package/Makefile:114: package/feeds/packages/unbound/compile] Error 1
make[2]: Leaving directory '/Volumes/OpenWrt/openwrt'
make[1]: *** [package/Makefile:108: /Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/stamp/.package_compile] Error 2
make[1]: Leaving directory '/Volumes/OpenWrt/openwrt'
make: *** [/Volumes/OpenWrt/openwrt/include/toplevel.mk:234: world] Error 2

Looks like this is another "curiosity" of Mac OS build environment, so I'll be doing some research on this. If anyone has any ideas about this or other Mac OS "gotchas" I should try to resolve, let me know.

Thanks

I'm also macOS user. But i found that difference between Mac and Linux as build environments are too hard to be fixed.

So i running few VMs under VirtualBox where i can built OpenWrt instead of fighting with differences.

Thanks for your reply. Yeah I was worried that's what others would say... I started out using Ubuntu in a VM but the clunkiness of it was just driving me crazy... drives not ejecting, windows getting stuck behind other windows, no command-C or command-V in terminal, issues sharing the buildroot using SMB so I could edit files and work on my module in Mac OS, etc...

I think us Mac users are more bothered by that sort of stuff lol. When I saw the "unofficial" guide on using Mac OS as a build environment that was right on the OpenWrt documentation site and it mentioned using the latest version of 10.15 (10.15.7), I had a lot of hope! It does seem to make it quite far into the build process, and plenty of things do seem to work without any tweaks as long as you use the GNU/homebrew version of various tools...

The latest update on the Mac OS(aga):

ccache gcc -DHAVE_CONFIG_H -I. -I..   -I/Volumes/OpenWrt/openwrt/staging_dir/host/include -I/Volumes/OpenWrt/openwrt/staging_dir/hostpkg/include -I/Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/host/include  -O2 -I/Volumes/OpenWrt/openwrt/staging_dir/host/include -I/Volumes/OpenWrt/openwrt/staging_dir/hostpkg/include -I/Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/host/include -MT rpc_util.o -MD -MP -MF .deps/rpc_util.Tpo -c -o rpc_util.o rpc_util.c
mv -f .deps/rpc_util.Tpo .deps/rpc_util.Po
ccache gcc  -O2 -I/Volumes/OpenWrt/openwrt/staging_dir/host/include -I/Volumes/OpenWrt/openwrt/staging_dir/hostpkg/include -I/Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/host/include  -L/Volumes/OpenWrt/openwrt/staging_dir/host/lib -L/Volumes/OpenWrt/openwrt/staging_dir/hostpkg/lib -L/Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/host/lib -o rpcgen rpc_clntout.o rpc_cout.o rpc_hout.o rpc_main.o rpc_parse.o rpc_sample.o rpc_scan.o rpc_svcout.o rpc_tblout.o rpc_util.o  
ld: warning: directory not found for option '-L/Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/host/lib'
Undefined symbols for architecture x86_64:
  "_libintl_gettext", referenced from:
      _main in rpc_main.o
      _usage in rpc_main.o
      _checkfiles in rpc_main.o
      _c_output in rpc_main.o
      _h_output in rpc_main.o
      _l_output in rpc_main.o
      _s_output in rpc_main.o
      ...
  "_libintl_setlocale", referenced from:
      _main in rpc_main.o
  "_libintl_textdomain", referenced from:
      _main in rpc_main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[6]: *** [Makefile:421: rpcgen] Error 1
make[6]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/hostpkg/rpcsvc-proto-1.4.2/rpcgen'
make[5]: *** [Makefile:391: all-recursive] Error 1
make[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/hostpkg/rpcsvc-proto-1.4.2'
make[4]: *** [Makefile:332: all] Error 2
make[4]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/hostpkg/rpcsvc-proto-1.4.2'
make[3]: *** [Makefile:51: /Volumes/OpenWrt/openwrt/build_dir/hostpkg/rpcsvc-proto-1.4.2/.built] Error 2
make[3]: Leaving directory '/Volumes/OpenWrt/openwrt/feeds/packages/libs/rpcsvc-proto'
time: package/feeds/packages/rpcsvc-proto/host-compile#4.06#3.83#9.49
    ERROR: package/feeds/packages/rpcsvc-proto [host] failed to build.
make[2]: *** [package/Makefile:112: package/feeds/packages/rpcsvc-proto/host/compile] Error 1
make[2]: Leaving directory '/Volumes/OpenWrt/openwrt'
make[1]: *** [package/Makefile:108: /Volumes/OpenWrt/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/stamp/.package_compile] Error 2
make[1]: Leaving directory '/Volumes/OpenWrt/openwrt'

This seems to be a well known occurrence since at least Mac OS 10.6, something about apple changing ld or clang or something, but I'm just so far out of my comfort zone here I have no idea where to begin or whether I should continue this fight to get OpenWrt to build on Mac... I really want to.

Well... I started taking a surgeon's approach - just cut out anything that looks suspect!

After removing a few packages (If I remember correctly: hwinfo, some kind of kernel "uring" thingy, luci-samba, samba4, lua-sqlite and sqlite, and maybe a few related ones) I finally got OpenWrt to build on Mac OS 10.15.7! Will update after I dd it and try booting.

make[2]: Leaving directory '/Volumes/OpenWrt/openwrt'
/Volumes/OpenWrt/openwrt/staging_dir/host/bin/ccache -s
cache directory                     /Volumes/OpenWrt/openwrt/.ccache
primary config                      /Volumes/OpenWrt/openwrt/.ccache/ccache.conf
secondary config (readonly)         /Volumes/OpenWrt/openwrt/staging_dir/host/etc/ccache.conf
stats updated                       Fri Jan 29 04:47:14 2021
cache hit (direct)                  5530
cache hit (preprocessed)            3384
cache miss                         37906
cache hit rate                     19.04 %
called for link                     2087
called for preprocessing            3230
multiple source files                 23
compiler produced stdout               1
compiler produced empty output       113
compile failed                      1913
ccache internal error                 19
preprocessor error                   939
bad compiler arguments               274
unsupported source language           20
autoconf compile/link               8214
unsupported compiler option            7
unsupported code directive             6
no input file                       1188
cleanups performed                     0
files in cache                     75434
cache size                         862.3 MB
max cache size                       5.0 GB
make[1]: Leaving directory '/Volumes/OpenWrt/openwrt'
kajteke:/Volumes/OpenWrt/openwrt$ 

That's gotta be the most long-awaited $ I've seen in a long time! :crazy_face:

That's what i've experienced too. That's why i install Ubuntu Server with SSH only. Once it's boot i use macOS SSH Client to login there and have Cmd-C, Cmd-V.

That's a good idea, and I'd have probably gone that route if I could have gotten SMB filesharing to work reliably. Most of my problems seemed to crop up when putting my Mac (and thus the VM) to sleep – waking up, all sorts of things would go haywire in the VM. Maybe if I have too many issues with my Mac OS build environment I'll go to a Ubuntu server VM on a desktop PC that's always on... oh yeah – burning coal just so my build environment can remain stable lol.

I'm definitely not an expert in these sorts of things.. usually I just need to look at a complex Linux build and it breaks down :tired_face:... but in case anyone is wondering, the main steps I used to get this working are basically to follow the "official unofficial" OpenWrt Mac OS build guide to get started, then:

The Brew packages I used:

brew install coreutils findutils gawk gnu-getopt gnu-tar grep make wget

And use the following /Volumes/OpenWrt/env.sh which is called with $ source /Volumes/OpenWrt/env.sh :

PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
PATH="/usr/local/opt/gnu-getopt/bin:$PATH"
PATH="/usr/local/opt/gettext/bin:$PATH"
PATH="/usr/local/opt/coreutils/bin:$PATH"
PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH"
PATH="/usr/local/opt/grep/bin:$PATH"
export PATH

I also included this patch in feeds/packages/net/unbound/patches/200-macos-fix.patch:

--- a/configure.ac	2020-12-03 09:31:18.000000000 +0100
+++ b/configure.ac	2021-01-26 01:16:58.000000000 +0100
@@ -120,6 +120,9 @@
 AC_SUBST(LIBUNBOUND_REVISION)
 AC_SUBST(LIBUNBOUND_AGE)
 
+# AC_CANONICAL_HOST is needed to access the 'host_os' variable
+AC_CANONICAL_HOST
+
 
 cmdln="`echo $@ | sed -e 's/\\\\/\\\\\\\\/g' | sed -e 's/"/\\\\"/'g`"
 AC_DEFINE_UNQUOTED(CONFCMDLINE, ["$cmdln"], [Command line arguments used with configure])
@@ -1226,15 +1229,15 @@
 AC_ARG_ENABLE(tfo-client, AC_HELP_STRING([--enable-tfo-client], [Enable TCP Fast Open for client mode]))
 case "$enable_tfo_client" in
 	yes)
-		case `uname` in
-			Linux) AC_CHECK_DECL([MSG_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])],
+		case "${host_os}" in
+			linux*) AC_CHECK_DECL([MSG_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])],
 			                     [AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])], 
 			                     [AC_INCLUDES_DEFAULT 
 #include <netinet/tcp.h>
 ])
 					AC_DEFINE_UNQUOTED([USE_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
 			  ;;
-			Darwin) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])], 
+			darwin*) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])], 
 			                      [AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])], 
 			                      [AC_INCLUDES_DEFAULT
 #include <sys/socket.h>

Added the following after line 16 to openwrt/staging_dir/host/include/asm/types.h:

// Mac OS-specific types:
#define __NR_bpf 515
typedef unsigned short __u16;  // NOLINT
typedef unsigned char __u8;
typedef unsigned int __u32;
typedef unsigned long long __u64;  // NOLINT
typedef __u64 __aligned_u64;
#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))

I'm sure there's a correct #ifdef to put this in, but __APPLE__ doesn't work, as the build environment seems to think it actually is __GNUC__? (Possibly because we're using gcc from brew? Like I said, I'm the village idiot here!) Either way, I just pasted it in at some haphazard location and it fixed the unknown type name '__u64' issue.

And I also don't expect any and all packages to compile. Things like hwinfo and KERNEL_IO_URING I'm not entirely sure why... and big unruly beasts like samba4 appear to be an exercise in futility to build on any OS that isn't a sanctioned Ubuntu version, based on what I've read at this point... so I've just disabled them and found replacements or workarounds. If I manage to get any of these working I'll try to include the methods I used.