Just add extern "C" before the function declaration. Because C++ supports function overloading and other things, the generated object code name will be somewhat different from C. Use extern "C" to force the C language name rules. Now the new version of the library seems to have been added. By the way, let me ask you where to download the new version of the library on the official website? I don't want to pop up the download link just by clicking
The header file of the new version of the library is
#ifdef __cplusplus
extern "C" {
#endif
later
#ifdef __cplusplus
}
#endif
2. Can't the interrupt function be entered?
Extern "C" should also be added before the interrupt function definition
3. Warning: #368-D: class "<unnamed>" defines no constructor to initialize the following:
I used this code to block the intermediate warning
#ifdef __cplusplus
extern "C" {
//Eliminate warning: #368-D: class "<unnamed>" defines no constructor to initialize the following:
#pragma diag_remark 368
#endif
...
...
#ifdef __cplusplus
//Recover Warning No. 368
#pragma diag_default 368
}
4,There will be errors after defining class variables throughout the book:
..\output\: Error: L6218E: Undefined symbol __cpp_initialize__aeabi_ (referred from anon$$).
The reason is that MicroLIB does not support c++, you just need to remove the Use MicroLIB in options to check it.
5,C++ has the new keyword, similar to C malloc, but this requires memory management to provide dynamic memory. What should I do on an MCU without an operating system?
In fact, there are already successful examples of using C++ abroad (it is just that IDE is not using MDK...). I downloaded the source code from the link provided by netizens:
/ws/2011/12/28/stm32plus-a-c-library-for-stm32-development/
(PS: After looking at their code base, I found that the file system I wrote before was really weak... It doesn't matter, I will continue to improve it)
This is what they do, using function overloading and reloading the new operator (software simulation will jump into the overloaded function)
, just provide some initialization of malloc, free and heap (this is usually memory-managed only if it is on OS...)
/* * Implement C++ new/delete operators using the heap */
void *operator new(size_t size)
{ return malloc(size); }
void *operator new[](size_t size)
{ return malloc(size); }
void operator delete(void *p)
{ free(p); }
void operator delete[](void *p)
{ free(p); }
Most of the problems are solved by referring to the methods of the predecessors, so I will sort them out here.