I'm trying to cross-compile kernel driver for WiFi dongle rtl8188eu and can't do this using sdk providing by buildroot.
I got this error for both internal and external toolchain:
In file included from ./include/asm-generic/int-ll64.h:11,
from ./arch/arm/include/uapi/asm/types.h:5,
from ./include/uapi/linux/types.h:5,
from ./include/linux/types.h:6,
from ./include/linux/list.h:5,
from ./include/linux/rculist.h:10,
from ./include/linux/sched/signal.h:5,
from /home/user/src/buildroot_external/output/vismut_x/build/r8188eu/include/osdep_service.h:25,
from /home/user/src/buildroot_external/output/vismut_x/build/r8188eu/core/rtw_cmd.c:23:
./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: No such file or directory
12 | #include <asm/bitsperlong.h>
| ^~~~~~~~~~~~~~~~~~~
But when I wrapped driver into buildroot package, it compiled and deployed just fine.
Actually I can see that I have file asm/bitsperlong.h in my sdk directory:
user@user-virtual-machine:~/sdk2$ find . -name bitsperlong.h
./opt/ext-toolchain/arm-none-linux-gnueabihf/libc/usr/include/asm/bitsperlong.h
./opt/ext-toolchain/arm-none-linux-gnueabihf/libc/usr/include/asm-generic/bitsperlong.h
./arm-buildroot-linux-gnueabihf/sysroot/usr/include/asm/bitsperlong.h
./arm-buildroot-linux-gnueabihf/sysroot/usr/include/asm-generic/bitsperlong.h
But it looks like buildroot's "environment-setup" script does not link to it.
The include directory
/home/user/sdk2/arm-buildroot-linux-gnueabihf/sysroot/usr/include/
is default include directory for cross-compilation: sysroot means that it's the subdirectory for the target system, /usr/include/ means subdirectory for all header files. All header files, located there, must be included without any problem, if build process is correctly configured.
To resolve the issue, modify CMakeLists.txt file of code you are building as follows:
# Adding include directory for the specific target
target_include_directories(your_target_name PUBLIC ${SYSROOT}/usr/include)
There is also possibility to use include_directories, although it's considered less preferable in modern cmake:
# Adding include directory for all targets
include_directories(${SYSROOT}/usr/include)
By default, the SYSROOT variable must be defined in environment-setup script. It may have different name, but it's supposed to be there. If it's not the case, the fix can be done. In the terminal, before running build process, export SYSROOT variable:
export SYSROOT=/home/user/sdk2/arm-buildroot-linux-gnueabihf/sysroot
Check that the variable was defined correctly:
echo $SYSROOT
Then run build process in the same terminal session with modified CMakeLists.txt file.