2016-12-24 05:00 PM
I set all the pins in CubeMx,
added a class to a .h file
renamed main.c to main.cpp
included the .h
and 'class' is undefined.
is there a switch in Cube for this ?
using an '091
#class-undefined #uv5 #keilSolved! Go to Solution.
2016-12-24 05:52 PM
Needs to be a .CPP file that does the including, or you need to add the --cpp to enable compiler support. ie compile .C as C++
2016-12-24 05:52 PM
Needs to be a .CPP file that does the including, or you need to add the --cpp to enable compiler support. ie compile .C as C++
2016-12-24 06:57 PM
Hey it worked.
Project options c/c++
in Misc Controls
add --cpp
2016-12-24 07:03 PM
One has to watch for C++ name mangling, functions you wish to export to the vector table, for example, need extern 'C' prefix so they bind properly in the linker, rather than the WEAK ones. The SysTick Handler being one to watch in CubeMX/HAL
ie
extern 'C' void USART1_IRQHandler(void)
{
...
}
2016-12-24 07:10 PM
I am a new C programmer
:(
do you mean in the .cpp file :
extern 'C' void USART1_IRQHandler(void)
{...}
and in the .h file:
extern 'C' void USART1_IRQHandler(void);
I am totally unsure about the syntax/implementation of your advice.
2016-12-25 05:33 AM
Yes, for functions that must be called from C or assembler, and when compiled as C++, you must use this syntax so the name is exported cleanly, otherwise it will be mangled. The name mangling process used by the compiler causes a unique name based on the parameters input to and returned by a function.
https://en.wikipedia.org/wiki/Name_mangling
http://www.geeksforgeeks.org/extern-c-in-c/
In the STM32 case what would happen is that the weak/default functions would get linked into the vector table if the functions you compiled as C++ remained mangled. The result would be that your interrupts would go into the Default_Handler and get stuck in a while(1) loop, instead of the IRQHandler body code you supplied.