Kernel package builds with "wrong" header files

Hi,

This is a continuation of my effort to build a driver for Realtek 8812 USB dongle.
I have successfully built the driver using OpenWrt buildroot but it does not load at runtime:

Wed Dec 11 06:26:25 2019 kern.warn kernel: [14161.833162] rtl8812au: Unknown symbol cfg80211_connect_bss (err 0)
Wed Dec 11 06:26:25 2019 kern.warn kernel: [14161.834029] rtl8812au: Unknown symbol __ieee80211_get_channel (err 0)

The driver's Makefile lists mac80211 as a dependency, and I notice that the mac80211 package is part of backports-2017-11-01.

The driver source code has #include <net/cfg80211.h> of which there are two variants in the directory tree: one for the backports, and one which predates backports. It looks like the compiler chose the "old" variant but the kernel itself implements the "new" variant (because it includes mac80211).

How can I force the build system to use the mac80211 variant of <net/cfg80211.h>. ?
I suspect it's a matter of setting the correct -I flag for the compiler but I'm not sure how to specify it.

The package Makefile appears below.

Thanks
Jeremy Begg

#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# An attempt to support a 5GHz WiFi USB stick based on Realtek 8811AC chip,
# using the driver source code supplied with the USB stick.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/kernel-defaults.mk

PKG_NAME:=rtl8812au
PKG_RELEASE:=1

# PKG_SOURCE_PROTO:=git
# PKG_SOURCE_URL:=https://github.com/gnab/rtl8812au.git
# PKG_SOURCE_VERSION:=744ebd966f2d967097b780f8d84b683b403f6db2
# PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION)
# PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz

# PKG_VERSION=2019-09-06-$(PKG_SOURCE_VERSION)
PKG_VERSION=1.0

# PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION)

include $(INCLUDE_DIR)/package.mk

define KernelPackage/rtl8812au
  SUBMENU:=Wireless Drivers
  TITLE:=Driver for Simplecom NW601 801.11ac wireless dongle
  DEPENDS:= @USB_SUPPORT +kmod-cfg80211 +kmod-lib80211 +kmod-usb-core
  VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)
  FILES=$(PKG_BUILD_DIR)/$(PKG_NAME).ko
  AUTOLOAD=$(call Autoprobe,$(PKG_NAME))
endef

define KernelPackage/rtl8812au/description
  Kernel support for 802.11ac (5GHz) using SimpleCom NW601 USB dongle
endef

define Build/Compile
	$(MAKE) -d $(KERNEL_MAKEOPTS) M=$(PKG_BUILD_DIR) \
		USER_EXTRA_CFLAGS="-D_LINUX_BYTEORDER_SWAB_H -DCONFIG_BIG_ENDIAN -DRTW_USE_CFG80211_STA_EVENT" \
		USER_MODULE_NAME=$(PKG_NAME) \
		CONFIG_BT_COEXIST=n CONFIG_RTL8812A=y CONFIG_RTL8821A=n CONFIG_RTL8812AU_8821AU=m CONFIG_PLATFORM_I386_PC=n CONFIG_PLATFORM_MIPS_AR9132=y \
		src=$(PKG_BUILD_DIR) \
		modules
endef

$(eval $(call KernelPackage,rtl8812au))

Check ath10k-ct or mt76 for example of how to build against the mac80211/ backports packages. Your problem is that you're trying to build against the kernel's mac80211 stack, which isn't used by OpenWrt in favour of the external backports package (a backport of a, usually more current, (wireless-) driver stack than that of the target base kernel).

Thanks slh,

I have confirmed (using the -H compiler flag) that the correct header files are being read.
Yet the undefined symbols are still present. From the build log ...

  MODPOST 1 modules
WARNING: "__ieee80211_get_channel" [/home/jeremy/myWatt/Firmware/build_V4/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/rtl8812au-1.1/rtl8812au.ko] undefined!
WARNING: "cfg80211_connect_bss" [/home/jeremy/myWatt/Firmware/build_V4/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/rtl8812au-1.1/rtl8812au.ko] undefined!

How can I find which module (or source file) is referring to those symbols?
I've tried requesting a linker map but the following added to the package Makefile didn't do it:

TARGET_LDFLAGS+= -Map=$(PKG_BUILD_DIR)/rtl8812au.map

Thanks