cancel
Showing results for 
Search instead for 
Did you mean: 

stmcubemx convert c to c++

johannes_hellbeck
Associate II
Posted on May 05, 2017 at 20:10

Hello,

When I compile STM32CubeMX generated C file with my IDE ( OpenSTM32 last version)

to

C is ever think ok.

In the Project Explorer I convert to c++.

But when I change main.c

to main.cpp I get an error message “make: ***

http://www.openstm32.org/Drivers/Hans.o

Error 258�?.

Is there a solution available?

Thanks Johannes
  • OS windows 10

    Version: Mars.2 Release (4.5.2)

    STM32L432KU

    STM32Cube V1.0 Version 4.20.#
15 REPLIES 15
Posted on May 10, 2017 at 14:21

I think , that will be a good thing  ST, Atollic/AC6 work here together and look for a solution…

The best solution would be if Cube supported C++ out of the box.

Everything else would be just a workaround.

Posted on May 11, 2017 at 10:23

I have converted C project into C++ and had to solve issue with static objects.

The solution was to add definition for linker in *.ld file:

/* .ctors .dtors are used for c++ constructors/destructors */

.ctors :

{

PROVIDE(__ctors_start__ = .);

KEEP(*(SORT(.ctors.*)))

KEEP(*(.ctors))

PROVIDE(__ctors_end__ = .);

} >FLASH

.dtors :

{

PROVIDE(__dtors_start__ = .);

KEEP(*(SORT(.dtors.*)))

KEEP(*(.dtors))

PROVIDE(__dtors_end__ = .);

} >FLASH

So, don't forget also for this.

Tomas.

Posted on October 26, 2017 at 04:30

Hmm, can you give an example please?

I've never had any issue with any static objects (static class members? or static functions? or static local variables?)

Posted on October 29, 2017 at 21:11

Hello Valentin,

It was a long time ago, so I cannot find the right example but in general, it was like:

&sharpinclude 'myclass.hpp'

static MyClass my_object_of_class;

int main()

{

  my_object_of_class.call_method();

}

When I call 'call_method()' of object 'my_object_of_class' which is allocated above main(), without initialization of sections ctors and dtors, it fails. Now I cannot remember if it was necessary static allocation or if it also fails without static.

Tomas

Posted on October 30, 2017 at 20:04

Hmm, interesting. I never had that issue so far. But I will keep this in mind in case I run into problems. Thanks!

Jeanne Joly
Senior III
Posted on January 18, 2018 at 15:31

Hi all,

For your information, we do understand the need for you to generate C++ project and this need is well known internally.

However, for the moment, with the success of STM32CubeMX, we have a lot of requests/suggestions to study and many improvements to integrate.

And the C++ generation project item is not yet under study currently.

Sorry, for the inconvenience it may cause.

BR. Jeanne