MDK以及DS5等工具中主推的编译器已经更换为armclang编译器。而原来的armcc编译器已经不再更新,只是提供一些更新,所以我就对armclang进行了一些测试。
测试的芯片是STM32,使用ST公司最新推出的Cube HAL库。直接新建一个工程之后,直接将编译器更改为armclang编译不通过。
错误一:提供找不到‘__weak’
解决方案:"__weak"的定义是在stm32f1xx_hal_def.h文件中。其中有关于各种编译器的定义部分。理论上armclang应该是会定义__GNU__的,可能由于MDK的bug或是其它原因,这部分并没有定义,所以需要手动增加针对armclang编译器的定义。
修改后代码如下:
/**
******************************************************************************
* @file stm32f1xx_hal_def.h
* @author MCD Application Team
* @version V1.1.1
* @date 12-May-2017
* @brief This file contains HAL common defines, enumeration, macros and
* structures definitions.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT N