Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 8 months ago.
mbed with stm32cubemx, HAL_TIM_MspPostInit, multiply defined or undefined symbol
I am trying to use some code generated by cubemx when I use the init code generated in mbed main I get an undefined symbol for void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
This is declared at the top of the generated cubemx main.c file and is called by one of the inits but is implemented in stm32f7xx_hal_msp.c . There isn't an include for this file in cubemx main. When I try to do the same in mbed main I get an undefined symbol. When I add an include for stm32f7xx_hal_msp.c I get a multiply defined error.
How do I use void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); ?
1 Answer
7 years, 7 months ago.
Hello David,
I'm not sure that it will solve the issue but when declaring the function in the mbed's main.cpp file try to indicate that it's a C type function in order to prevent name mangling as follows:
extern "C" void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
Oherwise, since it's declared in a .cpp file, the C++ compiler would apply name mangling (modify the function's name before compilation) and won't find such function in the stm32f7xx_hal_msp.c file.
Thanks Zoltan, I think that might actually work, it certainly clears that error. I am still left with one error. The cubemx generated file stm32f7xx_hal_msp.c also has a declaration extern void Error_Handler(void); . I have void Error_Handler(void); declared and implemented in main.cpp but I get the compiler message Error: Undefined symbol Error_Handler (referred from stm32f7xx_hal_msp.NUCLEO_F767ZI.o). How do I declare/implement so that it satisfies the extern void Error_Handler(void); in stm32f7xx_hal_msp.c ?
posted by 24 Mar 2017