编译Buildroot_2020.02时遇到IndexError:list index out of range问题解决

具体报错

1
2
3
4
File "/home/book/Desktop/workspace_reload_linux_os/100ask_imx6ull-sdk/Buildroot_2020.02.x/output/host/lib/python3.8/site-packages/mesonbuild/dependencies/base.py", line 1204, in _get_cmake_info 'cmake_root': 
temp_parser.get_cmake_var('MESON_CMAKE_ROOT')[0], IndexError: list index out of range package/pkg-generic.mk:254: recipe for target '/home/book/Desktop/workspace_reload_linux_os/100ask_imx6ull-sdk/Buildroot_2020.02.x/output/build/host-libglib2-2.62.5/.stamp_configured' failed make[1]:
[/home/book/Desktop/workspace_reload_linux_os/100ask_imx6ull-sdk/Buildroot_2020.02.x/output/build/host-libglib2-2.62.5/.stamp_configured] Error 2 Makefile:84: recipe for target '_all' failed make:
[_all] Error 2

原因

Meson CMake版本/来源不匹配,导致Meson 在配置host-libglib2时读取 CMake 信息失败。

查看本地cmake版本为3.25而构建这个build root所需版本为3.15。

解决方法

1) 强制使用 Buildroot 自带的 host 工具(避免系统 cmake/meson)

在 Buildroot 顶层目录执行:

1
2
export PATH="$(pwd)/output/host/bin:$PATH"
export LC_ALL=C

设置PATH优先使用 Buildroot 自己编译的工具(如 cmake、meson、ninja、pkgconf 等),而不是系统里 /usr/bin/ 的版本,避免版本不兼容的系统工具干扰 Buildroot 的编译

LC_ALL是为了避免中文编码问题

先确保这些工具存在/可用:

1
2
3
output/host/bin/cmake --version || true
output/host/bin/meson --version || true
output/host/bin/ninja --version || true

如果缺少,就让 Buildroot 构建它们:

1
make host-cmake host-ninja host-meson host-pkgconf

可能会疑惑,明明在我的makefile中并没有host-cmake host-ninja host-meson host-pkgconf这些目标啊,为什么可以make生成呢?

之所以可以这样做是因为在当前makefile中已经包含package下的子makefile文件,代码如下:

1
include $(sort $(wildcard package/*/*.mk))

而对应的子makefile,如Buildroot_2020.02.x/package/cmake/cmake.mk中会通过$(eval $(cmake-package))等命令去构造host-cmake等编译目标。

2) 清理失败的包后重建

1
2
make host-libglib2-dirclean
make all -j4

3) 构建过程中保持 PATH 干净

构建全程都保持:

1
2
export PATH="$(pwd)/output/host/bin:$PATH"
export LC_ALL=C

避免系统的 /usr/bin/cmake 抢在前面被调用。