Skip to main content
SDel.19
Associate II
August 5, 2020
Question

Trying to port Arduino library (C++ library ) to STM32 CubeIDE (C project)

  • August 5, 2020
  • 3 replies
  • 4725 views

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

This topic has been closed for replies.

3 replies

TDK
August 6, 2020

> 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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Akuks.1
Associate
September 22, 2020

By doing so it is throwing an another error!

Nikita91
Lead II
August 6, 2020

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 ;
}

SDel.19
SDel.19Author
Associate II
August 7, 2020

I will try, thank you guys!