One sketch compiles, the other doesn't. Help please!

This sketch compiles on IDE v1.6.8

#define LED 13

int counter = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting");
  pinMode(LED, OUTPUT);

}

void loop() {
  digitalWrite(LED,HIGH);
  delay(30);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED,HIGH);
  delay(30);
  digitalWrite(LED, LOW);
  delay(100);
    digitalWrite(LED,HIGH);
  delay(30);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED,HIGH);
  delay(30);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED,HIGH);
  delay(300);
  digitalWrite(LED, LOW);
  delay(100);

//  counter = counter + 1;
}

However when the line counter = counter + 1; is uncommented, the compilation fails, thus:

C:\Program Files\Arduino\arduino-builder -dump-prefs -logger=machine -hardware “C:\Program Files\Arduino\hardware” -hardware “C:\Program Files\Arduino\portable\packages” -tools “C:\Program Files\Arduino\tools-builder” -tools

… huge amount of diagnotic wibble removed …

“C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc” -w -Os -Wl,–gc-sections -mmcu=atmega328p -o “C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\buildd81323694c12ea3bb0ce9dc970512070.tmp/ard-blink2.ino.elf” “C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\buildd81323694c12ea3bb0ce9dc970512070.tmp\sketch\ard-blink2.ino.cpp.o” “C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\buildd81323694c12ea3bb0ce9dc970512070.tmp/core\core.a” “-LC:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\buildd81323694c12ea3bb0ce9dc970512070.tmp” -lm
collect2.exe: error: ld returned 5 exit status

exit status 1
Error compiling for board Arduino Pro or Pro Mini.

The IDE is installed on an XP SP3 vn under Virtualbox 5.0.16 on a Linux Mint host.

The two attachments are screenshots. What I’d really like to know isn’t so much that the code works for other people, or what is going on “under the hood”, but how to fix it.

Thank you for your attention.

With or without the line uncommented it compiles for me

IDE 1.5.6-r2
Windows 7

Compiles fine for me either way under Windows 7 and IDE 1.6.8.

Both versions compile for me on IDE 1.5.6 and 1.6.3. I don't have anything more recent and I usually use 1.5.6

I am using Puppy Linux which is based on Ubuntu

...R

Just a friendly reminder to save people some time.
I'll reiterate:

What I'd really like to know isn't so much that the code works for other people, or what is going on "under the hood", but how to fix it.

Update: This sketch is for an Arduino Mini Pro. When I try changing the target device to (say) a Mega, or a Leonardo, it completes. Some other Arduino types have failed, too.

Of course you realize that part of the process of correcting something is identifying what the nature of the problem is in the first place. Comments that tell you it does compile under this-and-that tells you that it's likely not the IDE's mentioned, which should point you to your flavor of Linux, since Robin has it working on his version of Linux. Telling you what does work is, a priori, narrowing the field of what doesn't work. The snarky comment isn't going to help your cause here.

how to fix it.

One way to fix it would presumably be to use an IDE/OS combination that is known to work.

Have you tried a Google/forum search on the error message ?

I am sorry if this came across as sarcastic. That wasn't the intent.
I am sure that something as simple as this can't have sneaked through the release process undiscovered, so I am sure it WILL run on other instances. Hence the suggestion to focus on the "how to fix" rather than the "does it?"

I expect that others have come across this issue, as I did a web search and there seem to be other people experiencing this - but from 2015. I was hoping that one of them would be along and say "OK yes, all you have to do is ..... " or, alternatively "Everybody knows this code doesn't work on XP, any more"

Hence the suggestion to focus on the "how to fix"

Try reinstalling the IDE.
It works on my 1.6.8 on a Mac.

I am sure that something as simple as this can't have sneaked through the release process undiscovered,

You have quite a complex setup. It is unlikely to have been tested using IDE v1.6.8 installed on an XP SP3 vm under Virtualbox 5.0.16 on a Linux Mint host particularly as XP is no longer supported by Microsoft.

I think the problem is the version of ld.exe included with recent versions of Arduino IDE are not compatible with Windows XP. The solution found in https://forum.arduino.cc/index.php?topic=310950.msg2282115#msg2282115 was to take the file from an older version and replace the one in your current IDE version. That’s just the first post I found about the issue. You can probably find more information on this with a bit of searching.

Arduino Pro Micro? There seem to be a lot of boards called that, which are causing me a headache even now (not to compile but to upload). So make sure you have the correct board loaded when you compile.

If it's a Sparkfun Pro Micro make sure you have installed the necessary board descriptions (how to do this all on Sparkfun's website).

Also, given that Sparkfun admit their 'Pro Micro' is just a bootloader-modified Leonardo, does your code compile with that board setting? You could probably upload it using that setting too. I did this (inadvertently) and no harm came of it (yet).

FYI Windows 10 seems very picky on these virtual USB boards, whereas my Windows 7 laptop manages to get on with them just fine (uploading that is, compiling is fine on both platforms). So it could well be your esoteric development environment that is causing the issue (as already mentioned by Grumpy Mike).

pert:
I think the problem is the version of ld.exe included with recent versions of Arduino IDE are not compatible with Windows XP. The solution found in collect2.exe: error: ld returned 5 exit status - #27 by piroxilin - Programming Questions - Arduino Forum was to take the file from an older version and replace the one in your current IDE version. That's just the first post I found about the issue. You can probably find more information on this with a bit of searching.

I was going to suggest the same thing myself. I swapped to the version of "ld.exe" from IDE V1.0.6 and it cured my problem. (XP SP3)
Deja-vu - I remember this coming up only a week or two ago.

I had this error. Do you have another version of the IDE ?
If yes,look for ld.exe in the old version and replace the ld.exe in 1.6.5 with the old ld.exe

-Malhar

Now here’s a thing - I had ‘compile’ errors last night as part of my current project using a Sparkfun Pro Micro - I was using the Keyboard.h library but had inadvertently left the board as an Arduino Uno (as I had used that as part of a different project).

Now the Keyboard only ‘works’ with virtual USB devices so can’t be used with standard UNOs or Nanos - so it gave me an error, something like "Keyboard not available, are you sure you have added #include <Keyboard.h> in your sketch?

So what I’m saying is that you may get compilation errors for perfectly ‘good’ code but it is only ‘good’ when the correct board is selected.

(I won’t even mention that I also managed to brick the Pro Micro and had to unbrick it - oops, too late! I’ll mention all these dangers in the video that covers this device). It’s a damned finicky device that’s for sure (even Sparkfun acknowledge this).