Skip to main content
JMazu.1
Associate III
March 8, 2020
Question

Main project file type.

  • March 8, 2020
  • 3 replies
  • 1615 views

Hi Folks,

Just starting off and have a question regarding the file extension of the 'main' file.

One of the options in creating the project is the targeted language: C or C++.

No matter which I choose the 'main' file is always main.c

I want to create main.cpp.

Any ideas about how to achieve this?

Thanks.

This topic has been closed for replies.

3 replies

Pavel A.
Super User
March 8, 2020

If you don't generate the project with Cube or CubeIDE, all your files can be C++.

TL;DR you don't want the Cube-generated main.c file to be C++. Neither the other Cube-generated files.

They better should stay .c, as created.

Add your own c++ files to the project and enjoy C++.

--pa

Piranha
Principal III
March 8, 2020

You didn't thought that mentioning IDE could be useful? Anyway, do you know how to rename a file?

But, if you are talking about CubeMX code generation, then:

https://community.st.com/s/question/0D50X0000BFER0CSQX/cube32-feature-request-need-to-handle-cpp-files

JMazu.1
JMazu.1Author
Associate III
March 9, 2020

Thanks for the replies folks,

Yes, I did omit to mention I was using STM32CubeIDE, sorry.

I didn't think it was as simple as renaming file from main.c to main.cpp

Seems an odd way to get things going, the IDE should do it for you given that it asked me 'C' or 'C++'

Pavel A.
Super User
March 9, 2020

>  the IDE should do it for you given that it asked me 'C' or 'C++'

The IDE yes, but the code generator (the Cube) currently can only generate plain C.

This isn't likely to change soon (and many customers would object. #metoo).

-- pa