MCUKeil编译无法识别__WEAK问题

Posted ZHONGCAI0901

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MCUKeil编译无法识别__WEAK问题相关的知识,希望对你有一定的参考价值。

文章目录

1. Keil编译无法识别__WEAK问题

在使用Keil编译有时出现无法识别__WEAK的问题,截图如下:

错误log如下:

..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(72): error:  #77-D: this declaration has no storage class or type specifier
  __WEAK void Uart1_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(72): error:  #65: expected a ";"
  __WEAK void Uart1_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(73): error:  #77-D: this declaration has no storage class or type specifier
  __WEAK void LpUart0_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(73): error:  #65: expected a ";"
  __WEAK void LpUart0_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(74): error:  #77-D: this declaration has no storage class or type specifier
  __WEAK void LpUart1_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(74): error:  #65: expected a ";"
  __WEAK void LpUart1_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(75): error:  #77-D: this declaration has no storage class or type specifier
  __WEAK void Spi0_IRQHandler(void);
..\\..\\..\\..\\mcu\\common\\interrupts_hc32l13x.c(75): error:  #65: expected a ";"

解决办法:
因为在Keil中需要定义成__weak才会被识别,所以在头文件中定义__WEAKDEF如下,并且将报错的地方__WEAK修改为__WEAKDEF

#if defined (__ICCARM__)
#define __WEAKDEF            __WEAK __ATTRIBUTES
#elif defined (__CC_ARM)
#define __WEAKDEF            __weak
#else
#error    "unsupported compiler!!"
#endif

2. ARM系列编译工具链:__CC_ARM、__ICCARM__、__GNUC__、__TASKING__

为了解决上面报错的问题,定义了__ICCARM____CC_ARM,这里做一个说明:

__CC_ARM对应的平台是:ARM RealView:

RealView,是一套包含编译、调试和模拟的开发工具,需结合开发环境如uvision、eclipse或者CodeWarrior,形成集成开发环境来使用。

__ICCARM__对应的平台是:IAR EWARM:

Embedded Workbench for ARM 是IARSystems 公司为ARM 微处理器开发的一个集成开发环境(下面简称IAR EWARM)。比较其他的ARM 开发环境,IAR EWARM 具有入门容易、使用方便和代码紧凑等特点。

__GNUC__对应的平台是:GNU Compiler Collection:

GCC的初衷是为GNU操作系统专门编写的一款编译器。GNU系统是彻底的自由软件。

__TASKING__对应的平台是:Altinum Designer:

Altium Designer 是原Protel软件开发商Altium公司推出的一体化的电子产品开发系统,主要运行在Windows操作系统。这套软件通过把原理图设计、电路仿真、PCB绘制编辑、拓扑逻辑自动布线、信号完整性分析和设计输出等技术的完美融合,为设计者提供了全新的设计解决方案,使设计者可以轻松进行设计,熟练使用这一软件使电路设计的质量和效率大大提高。

3. 参考博客

https://blog.csdn.net/liurunjiang/article/details/115012785

以上是关于MCUKeil编译无法识别__WEAK问题的主要内容,如果未能解决你的问题,请参考以下文章

MCUKeil编译无法识别__WEAK问题

STM32的hal库中__weak函数前缀的作用

__weak 修饰符

Keil> 编译器特有的功能 > 关键字和运算符 > __weak

__attribute__((weak)):弱引用,可以不实现

GWT+Jetty JSP 编译器问题的解决方法? (Java 1.5 源代码级别无法识别)