I am using IDE 2.2.1 to program a Nano (old boot loader). Everything was working fine, but now I get errors compiling my code, so I tried to compile and upload the BLINK example. I get similar errors. If I switch to a Mega board everything complies fine. I have done all the basics - rebooted, reset the Nano, reinstalled the IDE.
Here are the errors I get when compiling BLINK:
C:\Users\spamw\AppData\Local\Temp\ccPPFTSd.ltrans0.ltrans.o: In function setup': C:\Users\spamw\AppData\Local\Temp\.arduinoIDE-unsaved2023926-15340-1wjp66o.rj1w\Blink/Blink.ino:28: undefined reference to pinMode'
C:\Users\spamw\AppData\Local\Temp\ccPPFTSd.ltrans0.ltrans.o: In function loop': C:\Users\spamw\AppData\Local\Temp\.arduinoIDE-unsaved2023926-15340-1wjp66o.rj1w\Blink/Blink.ino:33: undefined reference to digitalWrite'
C:\Users\spamw\AppData\Local\Temp.arduinoIDE-unsaved2023926-15340-1wjp66o.rj1w\Blink/Blink.ino:35: undefined reference to `digitalWrite'
collect2.exe: error: ld returned 1 exit status
Hi @MadCompSci. I'm going to ask you to post the full verbose output from a compilation.
This procedure is not intended to solve the problem. The purpose is to gather more information.
Please do this:
Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open.
Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
Click the "OK" button.
Select Tools > Processor > ATmega328P (Old Bootloader) from the Arduino IDE menus.
Select Sketch > Verify/Compile from the Arduino IDE menus.
Wait for the compilation to fail.
You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
Open a forum reply here by clicking the "Reply" button.
Click the <CODE/> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press Ctrl+V.
This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.
Click the "Reply" button to post the output.
In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:
Open a forum reply here by clicking the "Reply" button.
Click the "Upload" icon () on the post composer toolbar:
A dialog will open.
In the dialog, select the .txt file you saved.
Click the "Open" button.
Click the "Reply" button to publish the post.
Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.
My hypothesis is that the unexpected error is caused by the core cache having been corrupted in some way.
The core is where the fundamental Arduino API such as pinMode and digitalWrite. In order to reduce the time required to compile a sketch, Arduino IDE caches the compiled core the first time you compile for a given board configuration. It then reuses that cache for all subsequent compilations for that board until such time as the core is modified.
A separate core cache is used for when you have Tools > Processor > ATmega328P or Tools > Processor > ATmega328P (Old bootloader) selected so this would explain why the sketch compiles when you select Tools > Processor > ATmega328P.
The solution is to delete the core cache. That will force Arduino IDE to compile the core and make a new good cache. I'll provide instructions you can follow to do that:
If looking for it with your file manager or command line, note that the AppData folder is hidden by default. On Windows "File Explorer", you can make it visible by opening the "View" menu, then checking the box next to "☐ Hidden items".
Please be careful when deleting things from your computer. When in doubt, back up!
After that, try compiling the sketch again, hopefully the error will no longer occur.