2020-08-05 01:35 PM
Hi all!
I used to "work" with Arduino environment in the past. Now I passed to Eclipse based IDE and in this specific case I'm using STM32CUBEIDE to develop a C project for an F100 series MCU.
In the Arduino world I used often a library written in C++ (header file and cpp file) and I would really like to use the same library in this case too, obviously with the due modification because of the different hardware but it's not this the point.
This is the library: https://github.com/mathertel/OneButton
In order to do that I added 2 new files in my project called say mylib.h and mylib.cpp. Than I copied the original library code in theese files. I also included the header file in main.c and build the project but I get the following errors:
I believe the problem is in the C++ language and I have to say I've never used C++ in STM32CUBEIDE so maybe I miss some steps...
p.s. the errors are in the images
2020-08-05 08:04 PM
> I also included the header file in main.c
The library is written in C++. You cannot include a C++ header within a C file. The C compiler doesn't know about classes.
You'll need to rename main.c to main.cpp or find another method.
2020-08-06 02:20 AM
The trick is to jump from C in main.c to a C++ code.
Define a C++ file like cppentry.ccp wich contain something like:
extern "C" void cppEntry (uintptr_t arg)
{
// Delete these lines and insert your C++ code here
(void) arg ;
cppTest () ;
}
In the main .c insert:
// The C++ entry, for demo purpose.
// You can start your C++ code from there
void cppEntry (uintptr_t arg) ;
int main ()
{
// To start the C++ application: call cppEntry()
cppEntry (arg) ;
return 0 ;
}
2020-08-07 05:07 AM
I will try, thank you guys!
2020-09-22 03:19 PM
By doing so it is throwing an another error!