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

使用 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;  
}

加入上面函数后解决问题

你可能感兴趣的:(c语言,单片机,stm32)