IDE not recognising file type change from C to CPP

HI, Had a problem with the IDE. Create a new sketch main file (xx.ino) and added other other files (xx.h and xx.c). Then complied. Got an error "class not recognise did I mean ..."! This confused me for a while, anyway long story short I noted that the compiler needs the source file to be a xx.cpp for classes etc. Yeah, ok that's correct. No problem, I changed the file extension from xx.c to xx.cpp and recompiled. Still the same problem? Gave the same error message pointing to a location in the source file classed "xx.c"! What?!? That file does exist in the folder! Now very confused, after much mucking around I found that if I started a new sketch with the same files (all renamed to cpp) the sketch compiled fine.
It seems the IDE does not reread the file types once in the sketch, even if they change?
My question, is there anyway to force the IDE to reread the file types in a sketch?

Hi @Ausierob.

The Arduino developers are tracking this bug here:

You can do it by deleting the temporary build folder where the zombie file is still stored . I'll provide instructions you can follow to do that:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the "OK" button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to finish.
  6. Examine the contents of the black "Output" panel at the bottom of the Arduino IDE window. You will see the temporary sketch build folder in the compilation commands there.
    For example, if you saw this line of output:
    "C:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\per\\AppData\\Local\\Temp\\arduino\\sketches\\44903AA428159DEA0A2322AB6B3CD206/sketch_jan14a_copy_20240119071329.ino.elf"
    
    You can extract the build folder path:
    C:\\Users\\per\\AppData\\Local\\Temp\\arduino\\sketches\\44903AA428159DEA0A2322AB6B3CD206
    
  7. Delete the temporary build folder.
    :exclamation: The folder may be hidden by default in your file manager and terminal.
    :warning: Please be careful when deleting things from your computer. When in doubt, back up!

Now compile the sketch again. Arduino IDE regenerates the build folder if it is not present, so deleting the folder doesn't do any harm and will result in the zombie file being purged.

Thanks for the info!!

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.