writer.c:(.text._write_r+0x14): undefined reference to `_write‘

在Ubuntu环境下使用arm-none-eabi工具链编译STM32F4的ledtest程序时,遇到链接错误,提示找不到_write函数。问题在于程序调用了printf,而默认底层接口未定义。通过添加自定义的_write函数解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用 ubuntu 下编译 stm32f4 程序,使用arm-none-eabi-  工具链,报错如下:

/opt/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: warning: stm32f4/tests/ledtest/ledtest has a LOAD segment with RWX permissions
/opt/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: /opt/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(libc_a-writer.o): in function `_write_r':
writer.c:(.text._write_r+0x14): undefined reference to `_write'
collect2: error: ld returned 1 exit status
stm32f4/tests/ledtest/build.mk:19: recipe for target 'stm32f4/tests/ledtest/ledtest' failed
make: *** [stm32f4/tests/ledtest/ledtest] Error 1

错误内容就是找不到函数 _write()  ,原因是在linux 下调用了printf ,底层接口函数为:

int _write (int fd, char *pBuffer, int size)  
{  
    return size;  
}

加入上面函数后解决问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值