Can't get Blink (or anything else) to compile

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

exit status 1

Compilation error: exit status 1

How do I get the IDE to recognize the Nano?

Update - I can get BLINK to compile if I select the "ATMega328P", but I get the compile errors if I choose the "ATMega328P (Old Bootloader)"

Hi @MadCompSci. I'm going to ask you to post the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  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 Tools > Processor > ATmega328P (Old Bootloader) from the Arduino IDE menus.
  5. Select Sketch > Verify/Compile from the Arduino IDE menus.
  6. Wait for the compilation to fail.
  7. 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.
  8. Open a forum reply here by clicking the "Reply" button.
  9. 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.
    Code tags icon on toolbar
  10. Press Ctrl+V.
    This will paste the compilation output into the code block.
  11. Move the cursor outside of the code tags before you add any additional text to your reply.
  12. 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:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:
    Upload icon on toolbar
    A dialog will open.
  6. In the dialog, select the .txt file you saved.
  7. Click the "Open" button.
  8. 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.

FQBN: arduino:avr:nano:cpu=atmega328old
Using board 'nano' from platform in folder: C:\Users\spamw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
Using core 'arduino' from platform in folder: C:\Users\spamw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6

Detecting libraries used...
C:\Users\spamw\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Users\spamw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\spamw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs C:\Users\spamw\AppData\Local\Temp\arduino\sketches\AFB461F63262EFE98943DE750454DE8E\sketch\Blink.ino.cpp -o nul
Generating function prototypes...
C:\Users\spamw\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Users\spamw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Users\spamw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs C:\Users\spamw\AppData\Local\Temp\arduino\sketches\AFB461F63262EFE98943DE750454DE8E\sketch\Blink.ino.cpp -o C:\Users\spamw\AppData\Local\Temp\1428520497\sketch_merged.cpp
C:\Users\spamw\AppData\Local\Arduino15\packages\builtin\tools\ctags\5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives C:\Users\spamw\AppData\Local\Temp\1428520497\sketch_merged.cpp
Compiling sketch...
"C:\\Users\\spamw\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\spamw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\spamw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\eightanaloginputs" "C:\\Users\\spamw\\AppData\\Local\\Temp\\arduino\\sketches\\AFB461F63262EFE98943DE750454DE8E\\sketch\\Blink.ino.cpp" -o "C:\\Users\\spamw\\AppData\\Local\\Temp\\arduino\\sketches\\AFB461F63262EFE98943DE750454DE8E\\sketch\\Blink.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\spamw\AppData\Local\Temp\arduino\cores\arduino_avr_nano_cpu_atmega328old_dd62aba6fe58242e6ba1f785e4240bda\core.a
Linking everything together...
"C:\\Users\\spamw\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\spamw\\AppData\\Local\\Temp\\arduino\\sketches\\AFB461F63262EFE98943DE750454DE8E/Blink.ino.elf" "C:\\Users\\spamw\\AppData\\Local\\Temp\\arduino\\sketches\\AFB461F63262EFE98943DE750454DE8E\\sketch\\Blink.ino.cpp.o" "C:\\Users\\spamw\\AppData\\Local\\Temp\\arduino\\sketches\\AFB461F63262EFE98943DE750454DE8E/..\\..\\cores\\arduino_avr_nano_cpu_atmega328old_dd62aba6fe58242e6ba1f785e4240bda\\core.a" "-LC:\\Users\\spamw\\AppData\\Local\\Temp\\arduino\\sketches\\AFB461F63262EFE98943DE750454DE8E" -lm
C:\Users\spamw\AppData\Local\Temp\cc40Dw5I.ltrans0.ltrans.o: In function `setup':
C:\Users\spamw\AppData\Local\Temp\.arduinoIDE-unsaved2023926-19356-14ftxt7.1ec3\Blink/Blink.ino:28: undefined reference to `pinMode'
C:\Users\spamw\AppData\Local\Temp\cc40Dw5I.ltrans0.ltrans.o: In function `loop':
C:\Users\spamw\AppData\Local\Temp\.arduinoIDE-unsaved2023926-19356-14ftxt7.1ec3\Blink/Blink.ino:33: undefined reference to `digitalWrite'
C:\Users\spamw\AppData\Local\Temp\.arduinoIDE-unsaved2023926-19356-14ftxt7.1ec3\Blink/Blink.ino:35: undefined reference to `digitalWrite'
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

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:

Delete the folder at the following path:

C:\Users\spamw\AppData\Local\Temp\arduino\cores\arduino_avr_nano_cpu_atmega328old_dd62aba6fe58242e6ba1f785e4240bda\

:exclamation: 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".


:warning: 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.

That worked! Thanks so much for the quick response!

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