Continuing the discussion from Arduino IDE "Save As" Doesn't Change Editor :
I'm having the same problem. Something is amiss with save as. It can do some really weird things. As you have stated I also use the "save as" to start a new program. Ny problem goes a bit deeper. When programming an esp32 yesterday afternoon I had used the save as to copy some existing known good code as a starting point. Add a couple of print statement to the code, hit the compile button and I get a missing "h" file error from the compiler. no big deal - add the file and hit the compile again. Get a new missing "h" file from the compiler. This time I wake up and really look into whats going on. The compiler error has nothing to do with the current code. Not reference anywhere. Hmmm... then the light comes on - but it was referenced in code I was running in a previous edit session using a different piece of code. I decided to go along with the compiler to get all the "h" files it wanted. Then I get the " collect2.exe: error: ld returned 1" error. So I immediately delete the appdata...core files. Problem goes away!!
Start the whole process over this time letting the IDE create a new sketch. Copy/paste the wanted code into the newly created sketch and this time I have no issues. Edit the rest of the afternoon with no issues.
This is not the first time I have seen this. Just the first time
I was able to understand that there is a unwanted feature in the "save as" function. I now avoid using save as and things seem to be working as expected.
Hi @ravenable . Can you provide a detailed set of step-by-step minimal instructions we can follow to reproduce the fault?
It sounds somewhat like this known bug:
opened 11:18PM - 19 Jun 16 UTC
topic: code
type: imperfection
topic: build-process
### Describe the problem
The previous file persists in the sketch build folder … after a sketch code file with extension other than `.ino`/`.pde` is renamed.
🐛 This can result in spurious compilation errors or confusing bugs. Arduino CLI users can work around the bug by adding the `--clean` flag to their command, but the only workaround for Arduino IDE users is to manually clean the build folder.
### To reproduce
```text
$ arduino-cli version
arduino-cli.exe Version: git-snapshot Commit: a735ddfd Date: 2023-01-15T01:00:07Z
$ arduino-cli sketch new /tmp/FooSketch
$ echo "void asdf() {}" > /tmp/FooSketch/foo.cpp
$ arduino-cli compile --fqbn arduino:avr:uno /tmp/FooSketch
[...]
$ mv /tmp/FooSketch/foo.cpp /tmp/FooSketch/bar.cpp
$ arduino-cli compile --fqbn arduino:avr:uno /tmp/FooSketch
C:\Users\per\AppData\Local\Temp\arduino\sketch-2405C4C9F90028537C79B0744BCE536E\sketch\foo.cpp.o (symbol from plugin): In function `asdf()':
(.text+0x0): multiple definition of `asdf()'
C:\Users\per\AppData\Local\Temp\arduino\sketch-2405C4C9F90028537C79B0744BCE536E\sketch\bar.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Used platform Version Path
arduino:avr 1.8.6 C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
Error during build: exit status 1
$ ls "C:/Users/per/AppData/Local/Temp/arduino/sketch-2405C4C9F90028537C79B0744BCE536E/sketch"
bar.cpp bar.cpp.d bar.cpp.o foo.cpp foo.cpp.d foo.cpp.o FooSketch.ino.cpp FooSketch.ino.cpp.d FooSketch.ino.cpp.o
```
🐛 `foo.cpp` is still present in the build folder even though not present in the sketch. `foo.cpp` is compiled in addition to `bar.cpp` and the primary sketch file.
### Expected behavior
Files are always removed from the sketch build folder when no longer present in the sketch.
### Arduino CLI version
#### Original report
Arduino IDE 1.6.9
#### Last verified with
0.34.1
### Operating system
- Linux
- Windows
### Operating system version
- Mint
- 10
### Additional context
#### Workaround
<a name="workaround-cli"></a>
##### Arduino CLI users
Run an `arduino-cli compile` command with [the `--clean` flag](https://arduino.github.io/arduino-cli/dev/commands/arduino-cli_compile/#options).
<a name="workaround-ide"></a>
##### Arduino IDE users
1. Examine the compiler error message. It will show the path of the temporary build folder.
For example, in this error:
```text
C:\Users\per\AppData\Local\Temp\arduino\sketches\7930E8409AED6D4F4A4782CF985194E9\sketch\foo.cpp.o (symbol from plugin): In function `asdf()':
(.text+0x0): multiple definition of `asdf()'
C:\Users\per\AppData\Local\Temp\arduino\sketches\7930E8409AED6D4F4A4782CF985194E9\sketch\bar.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
```
The temporary build folder is:
```text
C:\Users\per\AppData\Local\Temp\arduino\sketches\7930E8409AED6D4F4A4782CF985194E9\sketch\
```
1. Delete the temporary build folder.
#### Additional reports
- https://github.com/arduino/arduino-cli/issues/1699
- https://github.com/arduino/arduino-cli/issues/2058
- https://github.com/arduino/arduino-cli/issues/2613
- https://github.com/arduino/arduino-cli/issues/2870
- https://github.com/arduino/arduino-ide/issues/970
- https://github.com/arduino/arduino-ide/issues/1316
- https://github.com/arduino/arduino-ide/issues/1691
- https://github.com/arduino/arduino-ide/issues/2323
- https://github.com/arduino/arduino-ide/issues/482#issuecomment-2188269824
- https://github.com/arduino/Arduino/issues/2072
- https://forum.arduino.cc/t/ide-and-compiler-clear/1077526
- https://forum.arduino.cc/t/changed-tab-name-in-sketch-still-linking-old-o-file/1046286
- https://forum.arduino.cc/t/weird-error-pointing-to-old-code/1113608
- https://forum.arduino.cc/t/ide2-bit-upset-need-help/1129513
- https://forum.arduino.cc/t/renamed-tabs-wont-go-away/1165338
- https://forum.arduino.cc/t/file-renaming-issue/1173234/6
- https://forum.arduino.cc/t/reorganizing-code-w-wire-h-library/1180211
- https://forum.arduino.cc/t/ide-not-recognising-file-type-change-from-c-to-cpp/1215993
- https://forum.arduino.cc/t/code-compiles-in-old-ide-but-not-the-new-one/1286767
- https://forum.arduino.cc/t/problem-while-defining-namespaces-with-it-own-cpp-and-hpp-files/1304403
- https://forum.arduino.cc/t/there-is-a-bug-in-the-wire-library-for-version-1-8-6-avr-boards/1336297/18
- https://forum.arduino.cc/t/new-version-of-arduino-ide-2-3-5-error/1371224/20
- https://forum.arduino.cc/t/how-to-clear-cache-from-ide/1374114
- https://forum.arduino.cc/t/ld-problems-with-multiple-source-files/1381506/6
- https://forum.arduino.cc/t/how-to-clear-cache-from-ide/1374114/12
---
<details>
<summary><b>Keywords</b></summary>
<p>
- rename
- header
- .h
- .cpp
- .c
- C++
</p>
</details>
### Issue checklist
- [X] I searched for previous reports in [the issue tracker](https://github.com/arduino/arduino-ide/issues?q=)
- [X] I verified the problem still occurs when using the latest [nightly build](https://www.arduino.cc/en/software#nightly-builds)
- [X] My report contains all necessary details
However, that is not known to be caused by a "Save As..." operation, so I'm not certain.