printf重定位

printf在编译阶段有可能会被转化为puts

如:

printf(“hello\r\n”)会被替换成puts

printf(“hello”)不会被替换成puts

可以使用命令arm-none-eabi-objdump -dS image.elf > image.s,生成反汇编文件,查看汇编内容

如果不想printf转化为puts有两种方法

1、编译阶段,使用-fno-builtin-printf,去除对printf的优化

2、链接阶段,使用如下命令,增加printf和puts的重定向

LDFLAGS += -Wl,--wrap,printf

LDFLAGS += -Wl,--wrap,puts

你可能感兴趣的:(linux,c语言)