Go Down

Topic: collect2.exe: error: ld returned 5 exit status (Read 143755 times) previous topic - next topic

Superkasper

Hey there!

Im new to arduino but ive got my first error message, that i dont know how to handle already.
When compiling my sketch it gives me the following error message:
Quote
collect2.exe: error: ld returned 5 exit status
I googled and found a lot of people having the same problem saying
Quote
ld returned 1 exit status
Notice it says 1 instead of 5 here.
Unfortunately I didnt understand any aproaches to the problem there so this is kind of my last hope.

What does this error mean and how do i fix it or work around it?

Thanks in advance!

MarkT

ld is the linker, the linker gave an error.

Have you turned on verbose reporting in the IDE (preferences menu I believe)?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Anders53

#2
Mar 28, 2015, 09:03 pm Last Edit: Mar 28, 2015, 09:31 pm by Anders53
Got the exact same compile error.

Before it happens, my Windows XP client opens a message box telling me :

"Ld.exe
Ld.exe found an error and stopped. We are sorry about the inconvenience.
If you had any work open, you might loose informations.
For further details click here"

(this is translated from my native language, meaning the exact phrasing may differ from native English Windows clients)

If you click for further details, you get the usual windows memory dump, which can be looked into in deeper detail. The message box is waiting for you to close it.

Then the Arduino compiler ends with that nasty error message.
It does not in any way gives a clue, turning on the verbose option.
The screen is filled up with status messages from each compiled item, and does not tell if you have an error.
It generates a list of illegible compiler function calls and parameters, which is not for human beings to understand.

The compiler simply stops the compiling session with that nasty error message.
Trying to decipher the last call and parameters does not make any sense.

Surely we have made a mistake in our code, but the compiler can not tell us which mistake it is, for any reason.
Looking around with Google, it seems to be a common problem with the latest Arduino compiler version 1.6.1

I do hope that more of you guys out there will comment on this issue  :smiley-eek-blue:

Anders53

These lines are the last compiler calls written with the verbose option enabled :

F:\Programmer\Arduino/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega328p -o E:\DOCUME~1\Anders\LOKALE~1\Temp\build8952766791426698499.tmp/CruiseControl.cpp.elf
E:\DOCUME~1\Anders\LOKALE~1\Temp\build8952766791426698499.tmp\CruiseControl.cpp.o
E:\DOCUME~1\Anders\LOKALE~1\Temp\build8952766791426698499.tmp/core.a -L
E:\DOCUME~1\Anders\LOKALE~1\Temp\build8952766791426698499.tmp -lm

collect2.exe: error: ld returned 5 exit status
Error compiling.

My Arduino program installation folder is : F:\Programmer\Arduino
My temp folder is : E:\DOCUME~1\Anders\LOKALE~1\Temp
And the sketch I'm working on is named "CruiseControl".

To me it looks like something is wrong with the Arduino version I have selected.
But the same error comes out, for Uno, Nano and Mini, which all utilises the same processor in R3 versions, namely the ATMega328P.

Anders53

@ Superkasper :

In my last post, the last compiler call is seen with its parameters.
Its a call to the compiler utility avr-gcc.exe, which have a long list of parameters and files (including the full path).

If you look into your lcal temp folder, you can find the files passed on as parameters to avr-cgg.
These files are found in "buildxxxxxxxxx.tmp" folder, and are created from previous executed compiler utilities.
The files themselves are not utterly interesting, as they are binary data files.

You will also find a range of "consolexxxxxxx.tmp" folders, each one created every time you run a compilation of your sketch, with the verbose option enabled.
In these folders you can find a copy of the screen dump during the compilation.

Being a noob to the Arduino environment I cannot make sense of these informations.
My hope is still that someone can throw some light on this.

Anders53

#5
Mar 29, 2015, 02:43 pm Last Edit: Mar 29, 2015, 02:50 pm by Anders53
This is a strange phenomen  8)

Just to try something, I changed the board setting to "Micro" - and now the sketch compiles with no errors  :smiley-roll-blue:

I have'nt got a clue on whats going on.
I have been looking over my Pin assignments again and again, and there is nothing that should upset the compiler :

const int analogInputPin = A0;     
const int PWMoutputPin = 9;           
const int LEDoutputPin = 13;           
const int enableInputPin = 4;

void setup()
{
  pinMode(enableInputPin, INPUT);     
  pinMode(LEDoutputPin, OUTPUT);     
  pinMode(PWMoutputPin, OUTPUT);
}

All pins are universal to all Arduino Uno family boards.

But now compilation works  :smiley-mr-green:  :smiley-confuse:
Still have some method problems that needs to be worked out

Anders53

#6
Mar 29, 2015, 04:24 pm Last Edit: Mar 29, 2015, 04:30 pm by Anders53
I finally came around the code that caused my strange compiler error.
Using the standard code exclusion technique with comment codes, I narrowed in the problem.

First I commented out my functions and function calls, one by one.
That showed me that a problem exists with my function getSpeedValue.
In here the expression
averageOfReadings = sumOfReadings / numberReadings;
causes the problem, since the compiler sails through once this expression is commented out.

The expression returns an integer, but not a rounded off integer, which I really want.
Other than that I can not figure out why the expression should cause a compiler error.

PS : I finally figured out how to submit code.
Code: [Select]

/* Cruise control logic

  Adjusts a PWM outpin pin, by comparing running A/D input to an initially set value.

  * The circuit :
  * A CruiseControl enable input is taken from an external relay contact.
  * This relay works as a bistable relay, set by the driver on a CC start switch button placed on the instrument panel.
  * The relay is self contained by the LED output pin and disengaged by either a clutch or brake pedal switch, or both.
  * The same relay is used to switch the speed signal between Throttle Pedal Sensor (TPS) value and the CC throttle
  * pedal value.
  * Extensive use of external protection circuits is a must, to protect the Arduino board against reverse or over voltages.

*/

// never changes, except at compile time on sketch revisions
const int analogInputPin = A0;           // Analog input A0 (connector pin 12)
const int PWMoutputPin = 9;              // Digital pin D9 output with PWM capability (connector pin 19)
const int LEDoutputPin = 13;             // Digital pin D13 output with onboard LED (connector pin 16) for enabling external relay
const int enableInputPin = 4;            // Digital pin D5 input (connector pin 23)
const int numberOfReadings = 5;          // we dont need more than 5 analog readings for smoothing (to be experimented)
const int sizeOfIncrement = 3;           // the maximum rate of change of speed (to be experimented)
const unsigned long debounceDelay = 100; // the maximum number of readings to decide a stable relay contact input (to be experimented)
const int initialPWMout = 13;            // initial value of PWM output pin to set a start point greater than 0, 13 = 5% duty cycle
const int maximalPWMout = 251;           // maximal value of PWM output pin that will cause a CC droput, 255 = 100% duty cycle

// working global variables
int PWMoutputValue = initialPWMout;      // PWM speed output value
int analogInputValue;                    // holds the current speed reading
int analogInputReference;                // holds a speed set reading for reference
int readingsArray[4];                    // array holding 5 speed readings (incl index 0) from the analog input
boolean cruiseControlEnable = false;     // CC active flag

void setup()
{
  pinMode(enableInputPin, INPUT);        // prepare the digital enable input
  pinMode(LEDoutputPin, OUTPUT);         // enable the onboard LED on D13 output pin
  pinMode(PWMoutputPin, OUTPUT);         // prepare the PWM output
  for (int arrayIndex = 0; arrayIndex < numberOfReadings; arrayIndex++) readingsArray[arrayIndex] = 0;  // initialize the 5 array places 0 - 4 holding the analog readings
}

void loop()
{
  if (cruiseControlEnable == false)      // CC is not enabled
  {
    cruiseControlEnable = getDebounced(debounceDelay);
    analogInputReference = getSpeedValue(numberOfReadings);  // keep speed reference value updated for instant use if CC is enabled
  }
  else  // CC enabled : calculate speed difference & send a corrected PWM output as throttle pedal value to maintain speed
  {
    analogInputValue = getSpeedValue(numberOfReadings);                                                       // get current speed value
    PWMoutputValue = maintainSpeed(analogInputReference, analogInputValue, PWMoutputValue, sizeOfIncrement);  // maintain speed
    cruiseControlEnable = engineOverload(PWMoutputValue, cruiseControlEnable, initialPWMout, maximalPWMout);  // drop out on overload
  }
}

int getSpeedValue(const int numberReadings)  // read analog input numberOfReadings times for smoothing
{
  // local variables
  int sumOfReadings;      // the running sum of analog readings
  int averageOfReadings;  // the average of the readings

  for (int arrayIndex = 0; arrayIndex > numberReadings - 1; arrayIndex++)
  {
    sumOfReadings -= readingsArray[arrayIndex];               // subtract the last reading
    readingsArray[arrayIndex] = analogRead(analogInputPin);   // read from the sensor
    sumOfReadings += readingsArray[arrayIndex];               // add the reading to the sum Of Readings
    delay(1);                                                 // delay in between readings for stability
  }
  averageOfReadings = sumOfReadings / numberReadings;         // calculate the average Of Readings
  return averageOfReadings;
}

// this function wont work as the initial millis() reading is not saved in a global, to be corrected
boolean getDebounced(const unsigned long debounceDelayTime)  // read the state of the relay contact, that enables the CC
{
  // local variables
  unsigned long lastDebounceTime;  // debounce time counter
  boolean enableInputReading;      // holds the current reading of enable input
  boolean lastEnableInputValue;    // the last actual state of enable input

  enableInputReading = digitalRead(enableInputPin);                             // read the enable input value into current reading
  if (enableInputReading != lastEnableInputValue) lastDebounceTime = millis();  // If the input changed, due to noise or state change, reset the debouncing timer
  if (millis() - lastDebounceTime >= debounceDelayTime)                         // if the reading has been stable for the debounce time, save it as correct state
  {
    lastEnableInputValue = enableInputReading;       // save the reading input pin state
    digitalWrite(LEDoutputPin, enableInputReading);  // turn on the LED if CC is enabled
  }
  return enableInputReading;                         // return debounced state
}


int maintainSpeed(int reference, int speedValue, int PWMvalue, const int increment) // correct any speedchanges
{
  // local variables
  int difference;                                                    // holds how far the speed is from reference

  if (reference != speedValue)                                       // speed has changed, correct it
  {
    difference = speedValue - reference;
    if (difference < 0)                                              // speed is decreasing, get it up
    {
      if (difference < !increment) PWMvalue += increment;            // increase throttle value
      else PWMvalue++;
    }
    if (difference > 0)                                              // speed is increasing, get it down
    {
      if (difference > increment) PWMvalue -= increment;             // decrease throttle value
      else PWMvalue--;
    }
    analogWrite(PWMoutputPin, PWMvalue);                             // update throttle pedal value
  }
  return PWMvalue;
}

boolean engineOverload(int PWMvalue, boolean CCenable, int initialPWM, const int maxiPWM)  // full throttle does not change speed
{
  if (PWMvalue > maxiPWM)                  // do we have a bottom throttle pedal value ?
  {
    CCenable = false;
    analogWrite(PWMoutputPin, initialPWM);   // set the throttle pedal value to 0
    digitalWrite(LEDoutputPin, 0);           // shut off the external relay and the indicator LED
  }
  return CCenable;
}




DerLehmi

I have exactly the same Problem as in the third Post in this Threat....and I really dont know what to do next....
First of all I installed Arduino (1.6.2) on my Main-PC with Windows 8, no Problems. I have written some Programs and tested them on an Uno, and it worked. But I also need Arduino on my Netbook (Windows XP). So I installed the same Version on my Netbook, and I also installed the Drivers successfully (there are lots of goodTutorials). But i got this error. I uninstalled and reinstalled 1.6.2. again, I thought the Security Software blocked sth and so I deactivated it, but this Error appeared again. After that I tried the same with 1.6.3 Windows Installer and after that with the ZIP-File, same results. What shall I do next?

52edcs10ma

#8
Apr 14, 2015, 11:01 pm Last Edit: Apr 14, 2015, 11:02 pm by 52edcs10ma
I have the same error of ld.exe first and than

Code: [Select]

collect2.exe: error: ld returned 5 exit status



Code: [Select]

#include <JeeLib.h>

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(4000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  Sleepy::loseSomeTime(4000);            // wait for a second
}


If you comment the last line Sleepy::loseSomeTime(4000); than you can compile it easy without any errors. I have also tried avr/sleep.h and got the same error :( I have used the same commands earlier this year with one of the older arduino versions and both were ok.




Anders53

Looks like a typical newbie problem.
We dont even know what we are doing wrong.

Since this thread, I have written a lot of code, and only seen this error message once again.
And that was again cleared by changing the Arduino type.

kupofire471

#10
Apr 16, 2015, 04:43 am Last Edit: Apr 16, 2015, 04:45 am by kupofire471
This also happens to me. "collect2.exe: error: ld returned 1 exit status".

#include <IRremote.h> - only happens when i put this into my code. Even after i take it out, it still throws the error

Changing the board to Micro, does work, but it will never upload for me.

Lore759

Hello,
I had the same problem, using IDE 1.6.3 on WinXP SP3 (my hardware is Arduino Uno).
I am sure it is not a code problem but a compiler problem...

Finally I worked around the problem disinstalling IDE 1.6.3 and installing an older version (I choosed 1.0.5). It works wery well.


f41_ardu

I have the same issue using 1.6.3 on an XP system (SP3).

After renaming ld.exe located in C:\Arduino\arduino-1.6.3\hardware\tools\avr\avr\bin into oldld.exe
it seems to work.

Unfortunately I can not share my code at this point in time. So could you please try if renaming ld.exe,which at least make it invisible to the Arduino IDE make the trick for you, too?

It seems to be so weired that I can't believe it. But all other of my projects work fine witj thyt approach.

The code with issues is still under development. And while using 1.0.6, 1.5.8 everything works pretty well for me.


 

DaDo1

Same error for me on Win XP. It is strange, just when code grow to certain number of lines. So I had to go back to IDE 1.0.6

But on this version SoftwareSerial does not work well. I have just simple sending tx and rx to hardware UART on 9600 both (read write when available from example). It worked perfectly on 1.6.3, now I am loosing chars. Does it mean SoftSerial was reworked in 1.6.3, may I use it in 1.0.6?

Thanks

jurs

Same error for me on Win XP. It is strange, just when code grow to certain number of lines. So I had to go back to IDE 1.0.6

But on this version SoftwareSerial does not work well.
SoftwareSerial doesn't work well with any version of Arduino.

Use "AltSoftSerial" instead!

With any version of Arduino the AltSoftSerial library will work much better than SoftwareSerial.

BTW: What's that for a weird upgrade policy you are using:
- operating system outdated since several years
- operating system not upgraded for 10 years or so
- Arduino IDE has to be upgraded to a version that's just a few days old?
Strange!

Go Up