# 排错 这里介绍了比较常见的编译错误。如果你遇到的错误不在其中,那么则可以通过更换编译工具和源码来尝试解决这个问题,或者询问有内核编译经验的大佬。精通c语言的也行。 ### /usr/bin/env: ‘python2’: No such file or directory 安装python2.7和python2.7-minimal软件包 ```bash sudo apt install python2.7 python2.7-minimal -y ``` 如果上述指令不管用请继续输入以下内容: ``` ln -sf /usr/bin/python2.7 /usr/bin/python2 ln -sf /usr/bin/python2.7 /usr/bin/python ``` ### /usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x50): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here 这通常意味着指定的binutils无法使用或路径不正确。 解决办法:编辑scripts/dtc/dtc-lexer.lex.c_shipped文件,然后修改 ```bash -YYLTYPE yylloc; +extern YYLTYPE yylloc; ``` 或者删除 ```bash -YYLTYPE yylloc; ``` 或检查binutils的路径是否正确。 ### -Werror,xxxxxxx: - 编译器不支持此参数 解决办法:找报错的文件相应Makefile,把含有-werror的都删 或者换一个支持此参数的编译器。 如果是lto的问题请在设备的内核配置文件中注释掉所有有关lto的选项。 - 代码问题或者选项未开启([参考这个pr](https://github.com/tiann/KernelSU/pull/549)) 解决办法: - 开启选项 - 修改代码 ### xxx.h not found 一般地这种错误报错的代码下面会有类似这样的字样 ``` ^ "comm.h" ``` 第一种: not found 解决办法:查找内核源码根目录有没有这个文件,如果没有需手动复制一份。 第二种:如上图所示 解决办法:找到同名文件复制到编译出错的文件的目录上。 - 第三种,有这个文件 解决办法:根据报错信息重命名内核源码文件夹名称或移动vendor文件夹到相应位置 ### drivers/kernelsu/ksu.c:60:2: warning: #warning ("KPROBES is disabled, KernelSU may not work, please check https://kernelsu.org/guide/how-to-integrate-for-non-gki.html") [-Wcpp] error, forbidden warning: ksu.c:60 没有开启CONFIG_KPROBES 解决办法:修改ksu.c第60行。或者开启kprobes相关功能。 注:[此pr](https://github.com/tiann/KernelSU/pull/549)已解决此问题。 ### drivers/kernelsu/ksu.h:7:2: warning: #warning "KSU_GIT_VERSION not defined! It is better to make KernelSU a git submodule!" [-Wcpp] error, forbidden warning: ksu.h:7 内核根目录KernelSU目录没有.git文件夹 KernelSU内核程序版本号为10xxx,其中xxx指kernelsu仓库[提交次数](https://github.com/tiann/KernelSU/commits)如果获取不到提交次数会显示版本为16。 解决办法:删除KernelSU文件夹并重新执行setup.sh ### 关于 -Werror 引发的报错: 例如: ``` ../drivers/input/touchscreen/oplus_touchscreen/touchpanel_common_driver.c:1673:25: error: this old-style function definition is not preceded by a prototype [-Werror,-Wstrict-prototypes] bool tp_boot_mode_normal() ^ 1 warning and 1 error generated. make[5]: *** [../scripts/Makefile.build:338:drivers/input/touchscreen/oplus_touchscreen/touchpanel_common_driver.o] 错误 1 make[4]: *** [../scripts/Makefile.build:642:drivers/input/touchscreen/oplus_touchscreen] 错误 2make[3]: *** [../scripts/Makefile.build:642:drivers/input/touchscreen] 错误 2 make[2]: *** [../scripts/Makefile.build:642:drivers/input] 错误 2 ``` 解决方法:编译命令添加`KCFLAGS=-Wno-error`禁用所有警告 ### 其他问题:待补充