I cannot compile my program because of random command

Hello

I have this short script :

int cas;
int led1 = 8;
int led2 = 9;

void setup (){
pinMode(10,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}

void loop(){
cas = 300 + random(500);
//Serial.println(cas);
led1 = random(8,11);
led2 = random(8,11);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
delay(cas);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
}

which I cannot compile.
I get this message :

collect2.exe: error: ld returned 5 exit status
exit status 1
Error compiling for board Arduino Nano.

when I modify it this way :
int cas;
int led1 = 8;
int led2 = 9;

void setup (){
pinMode(10,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}

void loop(){
cas = 300 + random(500);
Serial.println(cas);
led1 = random(8,11);
led2 = random(8,11);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
delay(cas);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
}

then everything works.
I tried it for Nano and Uno with the same result.
Could you please help me ?
Is it necessary to use line with Serial.println or Serial.print command?
Where can I find it in documentation?

Thank you

Have a nice day

Regards

Petr
zavrelovi.us@seznam.cz

Both compile for a Uno on my system

Which operating system are you using?

W XP SP3

Can anybody explain what this arror message means :

collect2.exe: error: ld returned 5 exit status
exit status 1
Error compiling for board Arduino Nano.

Or where I can find explanation of all error messages during compilation?
It could help identify my problem and find way to fix it.
Thank you

closed:
W XP SP3

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. If you do a bit of searching you'll find more information. Which version of the Arduino IDE are you using?

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. If you do a bit of searching you'll find more information. Which version of the Arduino IDE are you using?

I can also verify that this is sometimes the best answer. I had problems receiving the same error for no apparent reason early on, (IDE V1.6.5 R5, UNO R3, WinXP SP3), so replaced the supplied ld.exe with a copy from IDE V1.0.6 and have never had a problem since.

I kept the original ld.exe and simply renamed it, just in case, but I've never needed it.

I've attached the copy of ld.exe from IDE V1.0.6 that cured my problem. (Zipped)

ld.zip (336 KB)

closed:
Can anybody explain what this arror message means :

collect2.exe: error: ld returned 5 exit status
exit status 1
Error compiling for board Arduino Nano.

Or where I can find explanation of all error messages during compilation?
It could help identify my problem and find way to fix it.
Thank you

Those are actually the last few lines of the compiler/linker output. The output window where they occur can be made bigger (or you can scroll through it) and you can see the 'real' error message. Some IDE versions have a button in the top bar of the output window that you can use to copy the error message.

You can post the complete message here between code tags
[code] your error message here [/code] will result in

 your error message here

You can use the same code tags to post code.

When I swap back to the version of ld.exe that was supplied with V1.6.5, then compile the code that 'closed' posted, (without the Serial.println()'), I get an unhandled exception in ld.exe.

When I compile with the version of ld.exe that I took from the IDE V1.0.6, I get no such error and it compiles without incident.