cancel
Showing results for 
Search instead for 
Did you mean: 

Use of library in STM IDE. How to consume cpp code? The library compiles if I have classes but as soon as I try to reference from main.c for example it even does not recognize instruction new, for example

FMarr.2
Associate III
 
6 REPLIES 6
Ozone
Lead II

Your problem description seems to miss some details.

The more detailed your description, the better the answers will match.

C and C++ calls are not directly compatible, cf. name-mangling.

You would need to declare every C++ function callable from C as "extern "C" ".

FMarr.2
Associate III

Well,

I started from a project of a STM Workshop.

Then I added a second project that is of type static library and for the same Discovery Board.

I started typing some C++ classes in the library and everything compiles. Then I added

a reference to the Library project and from the main project I can see the types of the library.

Then i added an Initialize.h file in which i declared a function in Initialize.cpp with decoration extern "C"

but inside this function I cannot type any C++ code.

Attached is the project , If you could please take a look.

Regards

FMarr.2
Associate III

I cannot understand, I used the same procedure used fro touchgfx and they are cpp code. I think somehow it does not recognize cpp in the library

when imported but the library is created in C++. I checked the option when i created.

Sorry, but I don't use Cube/HAL or STM Workshop. Nor touchgfx.

> Then i added an Initialize.h file in which i declared a function in Initialize.cpp with decoration extern "C"

Does this mean, you want to use a C++ library from a C code application ?

Then why not sticking to C++ ?

And if both are C++, you do not need to restrict the library to the C linker capabilitites.

FMarr.2
Associate III

Possible.

Not all the code of the project is C++, some code especially drivers are in C++.

This is not a problem

In CubeIDE, right click on the project and select "convert to C++"