STM32
直播中

发生的方式

8年用户 1229经验值
擅长:处理器/DSP
私信 关注
[问答]

Eclipse环境STM32工程编译报错undefined references to `assert_failed\'的原因?

用Eclipse环境创建一个STM32F407工程。编译时出现错误。c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:UsersHuichengeclipse-workspaceExcise-F407F407STDLibraryProjectDebug/../STM32F4xx_StdPeriph_Driver/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c:188: undefined reference to assert_failed' c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:UsersHuichengeclipse-workspaceExcise-F407F407STDLibraryProjectDebug/../STM32F4xx_StdPeriph_Driver/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c:189: undefined reference toassert_failed'c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:UsersHuichengeclipse-workspaceExcise-F407F407STDLibraryProjectDebug/../STM32F4xx_StdPeriph_Driver/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c:190: undefined reference to assert_failed' c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:UsersHuichengeclipse-workspaceExcise-F407F407STDLibraryProjectDebug/../STM32F4xx_StdPeriph_Driver/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c:208: undefined reference toassert_failed'c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: ./STM32F4xx_StdPeriph_Driver/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.o:C:UsersHuichengeclipse-workspaceExcise-F407F407STDLibraryProjectDebug/../STM32F4xx_StdPeriph_Driver/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c:215: more undefined references to `assert_failed' followcollect2.exe: error: ld returned 1 exit status。
检查stm32f4xx_gpio.c,stm32f4xx_gpio.h,.定义有。为什么报错


回帖(1)

靓仔峰

2024-3-20 17:12:30
这个错误是因为在编译过程中,链接器无法找到`assert_failed`函数的定义。

`assert_failed`函数是在STM32标准外设库中定义的一个回调函数,用于处理断言错误。当在程序中使用了`assert_param`宏时,如果断言失败,就会调用`assert_failed`函数。

解决方法是在工程中提供`assert_failed`函数的定义。你可以在你的工程中创建一个名为`stm32f4xx_assert.c`的源文件,并在其中进行函数的定义。示例代码如下:

```c
#include "stm32f4xx_assert.h"

void assert_failed(uint8_t* file, uint32_t line)
{
  // 处理断言错误的逻辑
  while(1) {
  }
}
```

然后将该文件添加到你的工程中,并确保编译器能够正确地找到它。

这样就可以解决`undefined reference to 'assert_failed'`错误了。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分