2017-06-26 02:49 AM
Hi,
I want to use STM32CubeMX and I would like to program my new project in C++. I am using the latest version of STM32CubeMX (4.21.0) and the latest version of Keil uVision (5.32.0.0).
After code generation I have added the compiler flag '--cpp'. I haven't added any custom code yet. But when I compile the project I get the following error. Without the compiler flag everything compiles and links without an error or warning.
compiling main.c...
../Inc/adc.h(62): error: &sharp337: linkage specification is incompatible with previous '_Error_Handler' (declared at line 162 of '../Inc/main.h')
extern void _Error_Handler(char *, int);
The function declarations for '_Error_Handler' seems to be correct. In main.c the function declaration is included from main.h and from every peripheral-header. In main.h the declaration does not have an 'extern' specifier. That seems to be the only difference. When I remove the function declaration for '_Error_Handler' in main.h, it works.But is that the correct way of programming in C++ with STM32CubeMX projects? If so, I would need to remove the declaration of '_Error_Hanlder' every time I re-generate the code.
#c++ #cpp #stm32cubemx*2017-06-26 02:57 AM
I don't know if keil is able to change the programm into C++ but I know that Eclipse can use C and also C++ language
2017-06-27 07:24 AM
Keil does support C++. You have to add the compiler-flag C++. But the generated code from the current STM32CubeMX version seems to have a problem with C++.
If I comment out the Error_Handler declaration in main.h everything compiles and links. But with the declaration 'void _Error_Handler(char *, int);' in main.h there is a linkage error.
2017-08-23 01:59 PM
Hi,
Error_Handler() interface present in main.h is not specified to be used in C-style linkage as it's done in the rest of the code.
Add
#ifdef __cplusplus extern 'C' { #endif
_Error_Handler(char *, int);
#ifdef __cplusplus}#endif
in the main.h to resolve the problem.
see
https://community.st.com/0D50X00009XkXpXSAV
Nig Oros