I am currently trying to set up CMock for unit testing the STM32 using MinGW and CMake. In my config file, I set the :weak: option so that the generated mock would give me weak functions. One example is:
#if defined (__IAR_SYSTEMS_ICC__)
#pragma weak HAL_TIM_IC_Init
#else
HAL_StatusTypeDef __attribute__((weak)) HAL_TIM_IC_Init(TIM_HandleTypeDef* htim);
#endif
HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef* htim)
{
...
}
However, when I compile, it gives me undefined reference to HAL_TIM_IC_Init error.
If I remove the weak
attributes, then it would not give me the undefined reference error. But because I need to override some function provided by the HAL layer, I need to make the mocked library as weak, otherwise it will give me multiple definition errors.
So my question is why the weak attribute caused the undefined reference error and how can I work around it?