Linux 6.13.4及以上版本内核编译时如何传递编译器选项?
Linux 6.13.4+ 自定义优化标志编译内核失败问题及解决方法
从Linux 6.13.4版本起,无法再通过自定义优化标志编译内核。在Linux 6.13.2版本中,以下命令可正常运行:
make CFLAGS='-march=native -Os -ffast-math -flto -pipe' CXXFLAGS='-march=native -Os -ffast-math -flto -pipe'
但升级到Linux 6.13.6版本后,编译时出现如下报错:
CC /home/user/Téléchargements/linux-6.13.6/tools/objtool/libsubcmd/exec-cmd.o exec-cmd.c:2:10: fatal error: linux/compiler.h: No such file or directory 2 | #include <linux/compiler.h> | ^~~~~~~~~~~~~~~~~~ compilation terminated.
解决方法
问题已解决,使用以下命令即可完成编译:
export KCFLAGS=" -march=native -Os -ffast-math" export KCPPFLAGS=" -march=native -Os -ffast-math" export KRUSTFLAGS=" -C target-cpu=native" make
补充说明:-flto选项无法生效,推测此前的编译命令实际并未正常启用该选项。
内容的提问来源于stack exchange,提问作者anclarma
相关产品推荐
相关产品推荐

