华大单片机KEIL报错_WEAK的解决方案
1. Keil编译无法识别__WEAK时的问题清单如下:
提示的错误信息如下:
........mcucommoninterrupts_hc32l13x.c(72): error: #77-D: this declaration has no storage class or type specifier __WEAK void Uart1_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(72): error: #65: expected a ";" __WEAK void Uart1_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(73): error: #77-D: this declaration has no storage class or type specifier __WEAK void LpUart0_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(73): error: #65: expected a ";" __WEAK void LpUart0_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(74): error: #77-D: this declaration has no storage class or type specifier __WEAK void LpUart1_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(74): error: #65: expected a ";" __WEAK void LpUart1_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(75): error: #77-D: this declaration has no storage class or type specifier __WEAK void Spi0_IRQHandler(void); ........mcucommoninterrupts_hc32l13x.c(75): error: #65: expected a ";"
解决办法: 因为在Keil中需要定义成__weak才会被识别(非大写的_WEAK),所以在头文件base_types.h文件中添加如下几行定义,编译就OK啦!
#if defined (__ICCARM__) #define __WEAK __WEAK __ATTRIBUTES #elif defined (__CC_ARM) #define __WEAK __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系统是彻底的自由软件。
