“Buildroot交叉编译内核模块: ‘致命错误: asm/bitsperlong.h: 没有该文件或目录'”

huangapple go评论83阅读模式
英文:

Buildroot cross-compiling kernel module: "fatal error: asm/bitsperlong.h: No such file or directory"

问题

我正在尝试交叉编译rtl8188eu WiFi dongle的内核驱动程序,但无法使用Buildroot提供的SDK完成此操作。我在内部和外部工具链都遇到了这个错误:

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>
      |          ^~~~~~~~~~~~~~~~~~~

但当我将驱动程序包装成Buildroot包时,它编译并部署得很好。

实际上,我可以看到在我的SDK目录中有文件"asm/bitsperlong.h":

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

但看起来Buildroot的"environment-setup"脚本没有将其链接起来。

我尝试使用内部和外部工具链 - 未成功。
我尝试将驱动程序包装成Buildroot包 - 成功。

英文:

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 dirrectory:

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 looks like buildroot's "environment-setup" script does not link it

I tried use internal, external toolchain - unsuccess
I tried wrap driver into buildroot package - success

答案1

得分: 1

/home/user/sdk2/arm-buildroot-linux-gnueabihf/sysroot/usr/include/ 是交叉编译的默认包含目录:sysroot 表示它是目标系统的子目录,/usr/include/ 表示所有头文件的子目录。所有位于那里的头文件,在构建过程中如果正确配置了,都应该能够被无问题地包含。

要解决此问题,请按照以下方式修改你正在构建的代码的 CMakeLists.txt 文件:

#  添加特定目标的包含目录
target_include_directories(your_target_name PUBLIC ${SYSROOT}/usr/include)

也可以使用 include_directories,尽管在现代 cmake 中它被认为是较不优先的:

#  为所有目标添加包含目录
include_directories(${SYSROOT}/usr/include)

默认情况下,SYSROOT 变量必须在 environment-setup 脚本中定义。它可能有不同的名称,但应该存在。如果不是这种情况,可以进行修复。在终端中,在运行构建过程之前,导出 SYSROOT 变量:

export SYSROOT=/home/user/sdk2/arm-buildroot-linux-gnueabihf/sysroot

检查变量是否正确定义:

echo $SYSROOT

然后在相同的终端会话中运行带有修改后的 CMakeLists.txt 文件的构建过程。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月27日 18:31:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定