avr-ld.exe throwing exit status 5 error

I'm assuming there's a conflict somewhere in the SdFat library with the serial monitor. The following code throws the error.

#include <SPI.h>
#include <SdFat.h>   [color=red]<----- xxxxxxxxx[/color]

void setup()
{
  Serial.begin(9600);
  Serial.println("test");  [color=red]<----- xxxxxxxxx[/color]
}
void loop()
{
  
}

The error occurs on the Mega 2560. Rem out either line indicated and it compiles fine. I tried compiling on a Uno and it works. I mostly like working with the Mega, and run across these errors pretty often. Is there an easy way to fix these examples? I'd rather not mess with the libraries themselves. Can I use Serial3 and output that to the monitor? I'd prefer changing all the serial statements if possible. Any suggestions are welcome.

I just compiled it with Arduino IDE 1.6.8, Mega 2560, and SdFat from GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library with no errors. Which IDE version are you using and where did you download your SdFat library from?

I downloaded the one from github you linked. I should have mentioned I'm on an XP platform. What OS are you using?

1.6.5 IDE... and I really HATE that the forum makes me wait 5 minutes before I can post an edit

1.6.5 works also for me with Windows 7 but I think the problem is the newer versions of avr-ld.exe have problems with Windows XP. I've seen that people will take the file from an older version of the Arduino IDE and copy it into their new IDE installation and that solves the problem. Here's one forum post I just found that refers to this fix: collect2.exe: error: ld returned 5 exit status - #27 by piroxilin - Programming Questions - Arduino Forum there's probably more/newer information on this, that was just the first result I found. So I'd find the most recent version of the IDE that doesn't cause the issue and take the file from it to use with IDE 1.6.5. Hopefully that will help you out.

I remember doing that quite a few versions ago, but I'm concerned now that the linker will some how fail. There've been lots of changes in the ide since then. What exactly does the linker do?

Yes, it's definitely a bit of a hack, also notice that they are talking about hardware\tools\avr\avr\bin\ld.exe when you're having the error with hardware\tools\avr\bin\avr-ld.exe. Still, unless someone else can suggest a better solution I think it's worth a try, even if only to narrow down the cause of the problem. Just save the other copy of avr-ld.exe and it's simple enough to revert the change if it doesn't work.

There is another thing I just remembered... I'm not at the computer with the arduino software or I'd paste the compilation verbose log.... But I do remember this:

There are a series of files such as C:/documents/...../..../..../temp/blah blah. Each followed by a carriage return. The last one, just before it throws the error, is preceded by "-L". So, the error comes when the linker is trying to process a file that looks something like "-LC:/Documents.... etc". That could be something. Any ideas?

Weird, I tried the same sketch on a different computer... also with the XP operating system with 1.6.7 instead of ..5 It worked there. Will try upgrading the older version and try it again