Collect2.exe: error: ld returned 9 exit status

Hi Guys,
From past two days my IDE shows this error for every code even previous working code also. while google about this i got the result for error id 1 which is outdated libraries. so i tried that also by updating all libraries i installed and upgraded the ide to latest and even installed 2.3.3 also i got the same error. I enabled the verbose output and posted here. i tried new program that also same error. i am using atmega2560 pro mini board, i switched board manager AVR ATMEGA2560, megacore, optiboot all gave me the same result.

i just tried without any libraries simply on off relay to check the library issue that also returns same error


const int BLOWER = 44;
const int BURNER = 42;
const int EXHAUST = 40;

  
void setup() 
{
  // put your setup code here, to run once:
  pinMode(BLOWER, OUTPUT);
  pinMode(BURNER, OUTPUT);
  pinMode(EXHAUST, OUTPUT);
 }

void loop() 
{
  // put your main code here, to run repeatedly:
  
    delay(1000);
      digitalWrite(EXHAUST, HIGH);
   delay(1000);
      digitalWrite(EXHAUST, LOW);
    delay(1000);
    
      digitalWrite(BURNER, HIGH);
    delay(1000);
      digitalWrite(BURNER, LOW);
  delay(1000);
      digitalWrite(BLOWER, HIGH);
    delay(1000);
      digitalWrite(BLOWER, LOW);
    delay(1000);
     
}
FQBN: MegaCore:avr:2560
Using board '2560' from platform in folder: C:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\3.0.2
Using core 'MCUdude_corefiles' from platform in folder: C:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\3.0.2

Detecting libraries used...
C:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega2560 -DARDUINO_ARCH_AVR -Wextra -flto -g -IC:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\3.0.2\cores\MCUdude_corefiles -IC:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\3.0.2\variants\100-pin-arduino-mega C:\Users\SIVANANTHAM\AppData\Local\Temp\arduino\sketches\A3E59C14CA651ADEE4586E81439DE6B2\sketch\io_test.ino.cpp -o nul
Generating function prototypes...
C:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega2560 -DARDUINO_ARCH_AVR -Wextra -flto -g -IC:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\3.0.2\cores\MCUdude_corefiles -IC:\Users\SIVANANTHAM\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\3.0.2\variants\100-pin-arduino-mega C:\Users\SIVANANTHAM\AppData\Local\Temp\arduino\sketches\A3E59C14CA651ADEE4586E81439DE6B2\sketch\io_test.ino.cpp -o C:\Users\SIVANANTHAM\AppData\Local\Temp\3992340859\sketch_merged.cpp
C:\Users\SIVANANTHAM\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\SIVANANTHAM\AppData\Local\Temp\3992340859\sketch_merged.cpp
Compiling sketch...
"C:\\Users\\SIVANANTHAM\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++17 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega2560 -DARDUINO_ARCH_AVR -Wextra -flto -g "-IC:\\Users\\SIVANANTHAM\\AppData\\Local\\Arduino15\\packages\\MegaCore\\hardware\\avr\\3.0.2\\cores\\MCUdude_corefiles" "-IC:\\Users\\SIVANANTHAM\\AppData\\Local\\Arduino15\\packages\\MegaCore\\hardware\\avr\\3.0.2\\variants\\100-pin-arduino-mega" "C:\\Users\\SIVANANTHAM\\AppData\\Local\\Temp\\arduino\\sketches\\A3E59C14CA651ADEE4586E81439DE6B2\\sketch\\io_test.ino.cpp" -o "C:\\Users\\SIVANANTHAM\\AppData\\Local\\Temp\\arduino\\sketches\\A3E59C14CA651ADEE4586E81439DE6B2\\sketch\\io_test.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\SIVANANTHAM\AppData\Local\Temp\arduino\cores\e8969f95c243b6f4de9b8d364ed8c714\core.a
Linking everything together...
"C:\\Users\\SIVANANTHAM\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -Wl,--gc-sections,--section-start=.FAR_MEM1=0x10000,--section-start=.FAR_MEM2=0x20000,--section-start=.FAR_MEM3=0x30000 -mmcu=atmega2560 -w -flto -g -o "C:\\Users\\SIVANANTHAM\\AppData\\Local\\Temp\\arduino\\sketches\\A3E59C14CA651ADEE4586E81439DE6B2/io_test.ino.elf" "C:\\Users\\SIVANANTHAM\\AppData\\Local\\Temp\\arduino\\sketches\\A3E59C14CA651ADEE4586E81439DE6B2\\sketch\\io_test.ino.cpp.o" "C:\\Users\\SIVANANTHAM\\AppData\\Local\\Temp\\arduino\\sketches\\A3E59C14CA651ADEE4586E81439DE6B2/..\\..\\cores\\e8969f95c243b6f4de9b8d364ed8c714\\core.a" "-LC:\\Users\\SIVANANTHAM\\AppData\\Local\\Temp\\arduino\\sketches\\A3E59C14CA651ADEE4586E81439DE6B2" -lm
collect2.exe: error: ld returned 9 exit status

exit status 1

Compilation error: exit status 1

My first attempt to solve the issue would be to empty the cache after closing the IDE; remove the content from the below 2 directories and try to compile again.

  • C:\Users\SIVANANTHAM\AppData\Local\Temp\arduino\sketches
  • C:\Users\SIVANANTHAM\AppData\Local\Temp\arduino\cores

I did try to find out what return code 9 means but have not succeeded yet.

Thank you for your response. already I tried this, using ccleaner i cleared everything in temp folder. but the result is same.

Finally working. I uninstalled everything related to arduino and deleted the arduino folder in the "C:\Users\SIVANANTHAM\AppData\Local\Temp" and cleared registry. then i restart the system and installed arduino freshly. now working fine

Hi, I am facing the same problem. Could you mention all the folders and registries you had to uninstall?
Here are the things I did:
1.Running Revo uninstaller:
a. Ran default uninstaller.
b. Ran advanced Revo function.
i. Deleted registries.
ii. Deleted unwanted folders.
2.Manually removing files:
a. Deleted everything in Program Files
b. Deleted everything in Program FIles (X86)
c. Deleted '.arduinoide' in Users folder.
d. Deleted 'Arduino Ide' and 'Arduino Ide Updater' in Users/Appdata/Local
e. Deleted Local/Temp
f. Deleted all files in Appdata/Roaming
g. Deleted 'Arduino' in Documents

i just uninstalled arduino ide from windows control panel itself, then i cleaned the registry using ccleaner (you can use any). Then i manually deleted the arduino15 folder in Local\Temp. Then i installed freshly thats it.

same problem for me also.. please guide me to rectifiy

I tried above, still same error

Please help

Hi, I have the same problem.
I have also tried all of the above mentioned actions. But I have still the problem.
I would appreciate additional suggestions.
Thanks