You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在使用armclang的Makefile中,如何同时捕获屏幕输出到日志文件?

问题:捕获armclang编译日志到文件并同步显示在屏幕

当前Makefile内容

all: startup_armclang startup_armasm main_armclang

startup_armclang:
    armclang --target=arm-arm-none-eabi -march=armv7-r -DBL1 _DRAM_JUMP -E -x assembler-with-cpp ./startup.s > temp.s

startup_armasm:
    armasm --diag_style=gnu --brief_diagnostics -g --debug --keep --cpu=Cortex-R5 -I. -I./System -o startup.o temp.s
    rm -f temp.s

main_armclang:
    armclang -c --target=arm-arm-none-eabi -marm -march=armv7-r -mcpu=cortex-r5 -g1 --debug -O0 -fno-function-sections -fno-data-sections -mfloat-abi=soft -mfpu=none -I. -I./System Main.c -o Main.o -MMD -MF Main.d

已尝试方法的问题

  • 执行 make all > log:屏幕正常显示警告、错误,但log文件仅记录执行的命令,未包含警告和错误。原因是>仅重定向标准输出(stdout),而编译器的警告、错误信息输出到标准错误(stderr),这部分内容没被捕获。
  • 执行 make all 2>&1 | tee log:出现「Ambiguous output redirect」错误,原因是当前使用的shell(如csh/tcsh)不支持2>&1这种POSIX风格的重定向语法。

解决方案

方案1:切换到支持标准重定向的shell执行命令

如果当前shell是csh/tcsh,先切换到bash再执行命令:

bash
make all 2>&1 | tee build.log

或者直接通过bash执行单条命令:

bash -c 'make all 2>&1 | tee build.log'

2>&1将stderr重定向到stdout,tee命令会同时将内容输出到屏幕和写入指定的日志文件。

方案2:修改Makefile统一处理日志

如果希望每次执行make时自动记录日志,无需额外加命令,可以在Makefile中给每个编译命令添加日志处理逻辑:

# 定义日志文件路径
LOG_FILE = build.log
# 定义日志重定向规则
LOG = 2>&1 | tee -a $(LOG_FILE)

all: startup_armclang startup_armasm main_armclang

startup_armclang:
    armclang --target=arm-arm-none-eabi -march=armv7-r -DBL1 _DRAM_JUMP -E -x assembler-with-cpp ./startup.s > temp.s $(LOG)

startup_armasm:
    armasm --diag_style=gnu --brief_diagnostics -g --debug --keep --cpu=Cortex-R5 -I. -I./System -o startup.o temp.s $(LOG)
    rm -f temp.s

main_armclang:
    armclang -c --target=arm-arm-none-eabi -marm -march=armv7-r -mcpu=cortex-r5 -g1 --debug -O0 -fno-function-sections -fno-data-sections -mfloat-abi=soft -mfpu=none -I. -I./System Main.c -o Main.o -MMD -MF Main.d $(LOG)

-a参数让tee以追加模式写入日志文件,避免每次make覆盖之前的记录。

内容的提问来源于stack exchange,提问作者Carter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:16:06