cancel
Showing results for 
Search instead for 
Did you mean: 

Impossible to rename main.c into main.cpp in sample code?

AndrewBloom
Associate II

Hi,

I'm using the sample HID_Standalone (USB_Host) for the board NUCLEO-H723ZG. I tried to rename the file main.c into main.cpp to force compilation with g++ instead of gcc. This worked fine with an Hello World I studied before.
Unfortunately, a really weird behaviour appears. If I rename the file with right click -> rename, the file appears renamed on the IDE but the actual file on the filesystem stays main.c. If I open with right click->show in->system explorer it's still main.c. If I run the build project command it still looks for main.c. If I rename the file on the system explorer it says that file main.c is not found. If I rename subdir.mk in the core folder another one is generated and it still contains main.c.

How to rename correctly the file? Is this the expected behaviour?

 

5 REPLIES 5
TDK
Guru

Right click rename should be working. Works for me.

Could create a new file and copy over the contents and delete the old file. Convert the project to C++ so it looks for those sources.

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

Hi TDK,

apparently the files on this example, as shown on the eclipse/Cube IDE, are links. if I right click->show in->properties I can see the various parameters associated. It appears that when you rename them, the original file is not renamed, (but the link is). As a workaround, I removed the link main.c from the left panel on Cube, renamed it on the system explorer and then dragged/dropped the renamed file on the folder back on the left panel of Cube. At that point a pop up menu opens with some options for the new link.
Once that was done, I converted the project to C++, and now trying to figure out some compilation errors that arise. Thanks for the help. 

 

Pavel A.
Evangelist III

This can be if main.c in the eclipse project is a "linked file".  In this case the .project contains two different names, one shown in the project explorer tree and the real one. Example:

 

<linkedResources>
   <link>
     <name>Src/MAIN.CPP</name>
     <type>1</type>
     <locationURI>PARENT-2-PROJECT_LOC/Src/main.c</locationURI>
   </link>
...............
</linkedResources>

 

Very intuitive, duh.

 


two different names, one shown in the project explorer tree and the real one

Very intuitive, duh.


It's a sarcasm... Is it?

(Obviously always "very intuitive" 😅)