• 华大单片机KEIL报错_WEAK的解决方案


    1. Keil编译无法识别__WEAK时的问题清单如下:

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

    提示的错误信息如下:

    1. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(72): error: #77-D: this declaration has no storage class or type specifier
    2. __WEAK void Uart1_IRQHandler(void);
    3. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(72): error: #65: expected a ";"
    4. __WEAK void Uart1_IRQHandler(void);
    5. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(73): error: #77-D: this declaration has no storage class or type specifier
    6. __WEAK void LpUart0_IRQHandler(void);
    7. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(73): error: #65: expected a ";"
    8. __WEAK void LpUart0_IRQHandler(void);
    9. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(74): error: #77-D: this declaration has no storage class or type specifier
    10. __WEAK void LpUart1_IRQHandler(void);
    11. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(74): error: #65: expected a ";"
    12. __WEAK void LpUart1_IRQHandler(void);
    13. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(75): error: #77-D: this declaration has no storage class or type specifier
    14. __WEAK void Spi0_IRQHandler(void);
    15. ..\..\..\..\mcu\common\interrupts_hc32l13x.c(75): error: #65: expected a ";"

     解决办法:
    因为在Keil中需要定义成__weak才会被识别(非大写的_WEAK),所以在头文件base_types.h文件中添加如下几行定义,编译就OK啦!

    1. #if defined (__ICCARM__)
    2. #define __WEAK __WEAK __ATTRIBUTES
    3. #elif defined (__CC_ARM)
    4. #define __WEAK __weak
    5. #else
    6. #error "unsupported compiler!!"
    7. #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系统是彻底的自由软件。
     

  • 相关阅读:
    关于 re.sub 部分替换的解决办法
    STM32:串口发送
    【Flink】窗口(Window)
    服务器、云服务器、高防服务器都有什么优势呢?
    vue基础相关问题:vue指令和动态及计算机属性
    一键解锁,2022阿里顶会创新技术前沿进展
    【SAP消息号C6013】
    【从零开始学微服务】02.初识微服务
    【C++】记录一次代码优化,28490行代码优化到1401行代码
    AspNetCore7.0源码解读之UseMiddleware
  • 原文地址:https://blog.csdn.net/u014453443/article/details/125481959