cancel
Showing results for 
Search instead for 
Did you mean: 

unknown type name '__weak' after Building project

Wilson_0706
Associate II

Hi all :

last week i transform my system form WIN10 to mac os

so I need transform Keil MDK project to STM32CubeIDE

below is my step

1.using STM32Cube MX Created STM32CubeIDE project

( it can compile and download successful)

2.copy my BSP/ library form Keil MDK folder

3.add library path to

"Properties -> C/C++ General -> Paths and Symbols -> Includes ->GNU C"​

0693W000006FYZTQA4.png​and follow this article i check my project ids using GNU11

​https://community.st.com/s/question/0D50X00009Xka2a/weak-clang

0693W000006FYZYQA4.png​but I got the error message after Building project

../Drivers/Library/Src/button.c:232:1: error: unknown type name '__weak'

../Drivers/Library/Src/button.c:232:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'BTN_now'

make: *** [Drivers/Library/Src/subdir.mk:24: Drivers/Library/Src/button.o] Error 1

make: *** Waiting for unfinished jobs....

can some help me that , thanks

my environment

STMcubeIDE : 1.5.0

Mac os : macOS Big Sur (Intel i5 version)

B.R.

5 REPLIES 5
KnarfB
Principal III

The error message is misleading. __weak is compiler specific, syntax may vary among compilers. You may search in STM32CubeIDE generated code how the syntax should look like and imitate for your code. Maybe showing a little more code could help.

Wilson_0706
Associate II

Hi KnarfB : thank for your response

after that i found there have a lot of weak function implement in Hal library

such as

__weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hadc);
 
  /* NOTE : This function should not be modified. When the callback is needed,
            function HAL_ADC_MspDeInit must be implemented in the user file.
   */ 
}

so I try include "stm32l0xx_hal.h" to my own library

and that solve the problem

but it make me very confused , In my concept library shouldn't involve to hardware layer

0693W000006FZpIQAW.png0693W000006FZpXQAW.png

Ozone
Lead

Perhaps your compiler demands "__attribute__ ((weak))" ?

There is probably only a macro used which is defined in HAL and related to __weak. Look it up in our code by using the search, goto definiton etc.. functions of the IDE. You may also check the compilers manuals about weak.

weak allows overloading functions at the linker level, roughly comparable to virtual member functions in C++.

Wilson_0706
Associate II

Hi Ozone , KnarfB

Thank a lot for helping

I finally fine the define of weak function in STM32L0xx_HAL_Driver​

 0693W000006FemTQAS.pngand after define  __attribute__((weak)) , this problem was solved

I find another interesting problem about code size,

same project between KEIL and STMcudeIDE have huge different code size

I try solve this problem by this article

If i solve it , I will tell you that ​

​B.R.

In Cube ide

0693W000006Feq6QAC.png 0693W000006FeuSQAS.png

In Keil

0693W000006FetjQAC.png0693W000006FetoQAC.png