Showing results for 
Search instead for 
Did you mean: 

I can not create C++ project for NUCLEO-H745ZI-Q board.

Associate II

Hi Everyone,

I am trying to create C++ project for NUCLEO-H745ZI-Q board. When I used the project wizard, even though I selected the C++ project, it creates it as a C project. Because of this, IDE can not recognize "class" keyword. How can I solve the problem?

Thanks in advance. 

ST Employee

Hello @Catutigernos and welcome to the ST Community 😊.

I suggest you to take a look at the answers of this post. That should be helpful.

Best Regards.


To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


STM32CubeMX is only set up to produce C code. You can't change this.

You can add C++ to your project if you want though. You'll need to convert the project to C++ by right clicking it and selecting Convert to C++. This basically just adds the C++ compiler step and will interpret *.cpp files as such.

If you feel a post has answered your question, please click "Accept as Solution".

Hi @STTwo-32,

Thanks for your response. Actually I tried these things before, but when I create new project, that worked. Only issue, when I change the configuration, the IDE regenerate the codes as main.c not main.cpp and everything I done is gone. Actually, I do not understand that if the IDE will generate the code as C, why there is an option for C++. The post, you mantioned, asked two years ago and we face same issue today. I suppose it is not important for ST, so they have not done fix. I create the project as C++, so I expect the all configuration is done automatically according to C++. 

What you "expect" is not what ST implemented.  Yes, it would be nice if CubeMX was able to generate cpp files, but it can't.  If you use Cube to generate code, it will always create main.c.  You can either live with that, and have main() call an application_main() (or some such function) is a separate cpp file that can do C++ things, or you manually rename (or copy, or merge) main.c to main.cpp every time to re-gen the code.  Personally I just have main() from main.c call into a different cpp main function and be done with it.

Thanks for your response. I already selected the target language as C++, so when I click right, there is only "Convert to C" option. Selecting C or C++ not matter, always create main file as C. 

Thanks for your response. Renaming is not issue. Problem is the IDE generate codes in every configuration changes, so I lose everything done in main file. 

Pavel A.
Evangelist III

Normally CubeMX/IDE won't touch files added by user. So, if you follow the advice of Bob S. your custom c++ files will stay. Once there were regression issues when CubeMX/IDE deleted user files on re-generation, this has been fixed long ago. If your added files are deleted, please report a bug. Otherwise, as Bob S. and TDK advised, call your C++ "main" function from the cube-generated main.c. The user code section  /* USER CODE BEGIN WHILE */ is a good place to insert this call.  User-added code between  /* USER CODE BEGIN ... */ and  /* USER CODE END ... */  lines is preserved by Cube. Code that you've left anywhere else will be lost.


CubeMX is not set up to generate main.cpp. There is no changing this. It is not intended to create main.cpp even if you select a C++ project.

The only way to add C++ code and retain the "generate code" functionality is to put your C++ in a separate file and call it from main.c.

If you feel a post has answered your question, please click "Accept as Solution".