Keep getting collect2.exe*:error: ld returned 1 exit status Error creating .elf


Quite happy to say I'm complete noob at this despite having had a very successful 20 career in software development focusing on C, C++ and and Most recently and enjoyably C#. (I will disclaim that I'm pumped full of opioid baed medication due to severe hand injury might now which isn't' helping)

I have a bare bones app created by Visual Micro that just will not compile.

I'm using v1,6, have tried older versions and same result, I will just e happy when I can discover my device via the SmartThings shield.

here's the complete output of the Micro Build Output pane:

[code] Compiling 'SmartThingsRecliner' for 'Arduino/Genuino Uno' Build folder: file:///C:/Users/Lee/AppData/Local/V.Micro/Arduino/Builds/SmartThingsRecliner/uno Summary: Header=1 Prototypes=7 Imports=2 Additional Defines: Architecture Tools: C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/ Sketchbook: file:///C:/Users/Lee/Documents/Arduino/libraries/SmartThings Core Include Paths Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino' Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard' Library Include Paths (1) Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial' Platform Libraries Root Include Paths Include Path 'C:\Program Files (x86)\Arduino\libraries' Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries' Include Path 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\unqlgtb4.1ye\Micro Platforms\default\debuggers' Include Path 'C:\Users\Lee\Documents\Arduino\libraries\SmartThings\libraries' "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=165 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial" -I"C:\Program Files (x86)\Arduino\libraries" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries" -I"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\unqlgtb4.1ye\Micro Platforms\default\debuggers" -I"C:\Users\Lee\Documents\Arduino\libraries\SmartThings\libraries" "C:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno\SmartThingsRecliner.cpp" -o "C:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno\SmartThingsRecliner.cpp.o" Build Core Paths: C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno/SmartThingsRecliner.elf" "C:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno\SmartThingsRecliner.cpp.o" "C:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno\SoftwareSerial\SoftwareSerial.cpp.o" "C:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno/core.a" "-LC:\Users\Lee\AppData\Local\V.Micro\Arduino\Builds\SmartThingsRecliner\uno" -lm SmartThingsRecliner.cpp.o:In function loop' SmartThingsRecliner.ino:run()' SmartThingsRecliner.cpp.o:In function__static_initialization_and_destruction_0' SmartThingsRecliner.ino:SmartThings(unsigned char, unsigned char, void ()(String), String, bool)' SmartThingsRecliner.ino:~SmartThings()' collect2.exe:error: ld returned 1 exit status Error creating .elf [/code]

Can someone please help me get my code compiling and my device discoverable otherwise my free time off work due to to the hand injury will be largely wasted and expensive!

Thank you, Lee.

PS It's a Mac Mini Server natively running Windows 8.1. VS2012, Uno R3, latest SmartThings shield.

A bunch of people have had IDE 1.6.x problems, including IDE crashes and bizarre compile errors, when they have an old 1.5.x/1.6.x installation. Those problems seem to be caused by out-of-date executables that the new IDE saves outside the IDE installation directory. In such cases it appears that the fix is to delete or rename the old "Arduino15" directory and re-install 1.6.x.

On Mac OS X: /Users/username/Library/Arduino15

On Windows: C:\Users\username\AppData\Roaming\Arduino15

I had the same error message:

pushButtons.cpp.o:In function `setup'
collect2.exe*:error: ld returned 1 exit status
Error creating .elf

The problem was with namespaces in my library. Class methods were defined void setDebounceTime(int time) and this caused the error.

I have changed to void Button::setDebounceTime(int time) and this worked for me.


When I am typing the same thing (addition of button to function name) in the function name which I have given to one of my functions ; I got the error as Button not declared !!

Can you please help me to resolve the issue?

himanshumanghani: Hi,

When I am typing the same thing (addition of button to function name) in the function name which I have given to one of my functions ; I got the error as Button not declared !!

Can you please help me to resolve the issue?

  1. Your problem is not related to the OP's problem.
  2. Without seeing your code, no one can possibly help you.
  3. This is an old thread, why dig it up again?
  4. You shouldn't hijack someone else's thread anyway.

Start a thread of your own, in the "Programming Questions" section, (not here in "Installation & Troubleshooting"). When you do, please post your code, and describe the problem accurately. Ensure that your code is posted between [code]code tags[/code], not inline.

collect2.exe: error: ld returned 1 exit status

#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <RF24Network.h>
#include <RF24.h> 
OneWire ds(8);    //ds στην ψηφιακή θύρα 8
#include "DHT.h" // DHT11 ή 22 αισθητήριο υγρασίας 
#define DHTPIN 3 // στο pin 7 πηγαίνει το σήμα του αισθητήριου υγρασίας
#define DHTTYPE DHT22 // ο τύπος του αισθητήριου υγρασίας που χρησιμοποιούμε 
#define LED_light 5 // στο pin 5 πηγαίνει το σήμα του αισθητήριου φωτεινότητας LDR
#define CE_PIN 9  // το CE είναι στην θύρα 9
#define CSN_PIN 10  // το CSN είναι στην θύρα 10
RF24 radio (CE_PIN ,CSN_PIN) ; // Ασύρματη επικοινωνία που επισυνάπτεται σε ποιες θύρες
RF24Network network (radio) ;  // Το δίκτυο που χρησιμοποίει  η ασύρματη επικοινωνία
const uint16_t this_node = 1;
const uint16_t other_node = 0;
const unsigned long interval = 2000;  //μ second
unsigned long last_sent;      //  το τελευταίο πακέτο δεδομένων
unsigned long packets_sent;     // ποσά πακέτα έχουν αποσταλθεί 
int A;
int a=1024;
int d ;
int y=1024;
int x=A0;
int x2=A1;      //ακέραια μεταβλητή που την δέχεται από την αναλογική 1
int light_pin =A5;    //ακέραια μεταβλητή που την δέχεται από την αναλογική 5
float Humidity;     //δεκαδική μεταβλητή  σχετικής υγρασίας 
float T;
int nRainIn =A2;
int nRainDigitalIn =6;
int nRainVal;
boolean bIsRaining = false; //δυαδική μεταβλητή
String strRaining;      //χαρακτήρας
int Soil=0;
int Soilb=0;

struct payload_t  // η δομή payload δηλώνουμε ποιες μεταβλητές θα στέλνει μέσο της ασύρματης επικοινωνίας
  unsigned long ms; 
  int A;
  float Temp;
  int light_lvl;
  float Humidity;
  int Soil;
  int Soilb;
  int nRainVal;
  boolean bIsRaining;
  unsigned long counter;

void setup() {
Serial.println("Trasnfer data GReenHouse Arduinio RF24Network PSev/");
pinMode(LED_light, OUTPUT);    // δήλωση μεταβλητής σαν έξοδος
pinMode(nRainDigitalIn, INPUT);     // δήλωση μεταβλητής σαν είσοδος 
  network.begin(/*channel*/ 90, /*node address*/ this_node);

void loop() {
 byte i=0;
 byte present = 0;
 byte type_s;
  byte data[12];
  byte addr[8];
  float Temp;
network.update();     //ανανέωση δικτύου επικοινωνίας RF

if ( ! {
//    Serial.println("No more addresses.");
    // Serial.println();
  //  delay(250);
  Serial.print("ROM =");    // ROM READ ONLY DATA
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");

  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  //delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  present = ds.reset();;    
  ds.write(0xBE);         // Read Scratchpad
//  Serial.print("  Data = ");
//  Serial.print(present, HEX);
//  Serial.print(" ");
  for ( i = 0; i < 8; i++) {           // we need 9 bytes
    data[i] =;
//    Serial.print(data[i], HEX);
//    Serial.print(" ");
 // Serial.print(" CRC=");
  //Serial.print(OneWire::crc8(data, 8), HEX);

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time

Temp = (float)raw / 16.0; 
//με αυτή την διαίρεση  είναι η θερμοκρασία σε celsius στα αισθητήρια DS18b20
  Serial.print("  Temperature = ");
  Serial.print(" Celsius, ");

Humidity = dht.readHumidity();
T = dht.readTemperature();
Serial.print("Humidity: ");
Serial.println(" %");
int light_lvl=analogRead(light_pin);
int x = analogRead(A0);//take a sample
int x2 = analogRead(A1);//take a sample
Soil=y - x; // είναι 1024- x (το αποτέλεσμα του αισθητήρα) για να είναι κατά αύξουσα σειρά η υγρασία εδάφους 
Soilb = y - x2;
Serial.print("Soil_Sec =");Serial.println(Soilb);
  nRainVal = analogRead(nRainIn);
  bIsRaining = !(digitalRead(nRainDigitalIn));
    strRaining = "Yes";
    strRaining = "No";
  Serial.print("Raining: ");
  Serial.print("\t Moisture Level:");
d= ((a-light_lvl)/4); // με αυτή την πράξη ο όταν υπάρχει έλλειψη φωτός να υπάρχει φωτίζετε κατάλληλα
Serial.println(d);    // d είναι η έλλειψη φωτός 255 καθόλου φως 
if (d>80 )
analogWrite (LED_light,d);  //ρυθμίζει την φωτεινότητα τον led μέσω του Δίκτη d Serial.println ("LED ON");
  Serial.println("LED OFF");
  if (addr[0] == 0x28 && addr[1] == 0xFF && addr[2] == 0x35 && addr[3] == 0x08 && addr[4] == 0x63 && addr[5] == 0x04 && addr[6]==0x00 &&addr[7] == 0x78 )

else if (addr[0] == 0x28 && addr[1] == 0x8E && addr[2] == 0x21 && addr[3] == 0x05 && addr[4] == 0x07 && addr[5] == 0x00 && addr[6]==0x00 &&addr[7] == 0x29 )

else if (addr[0] == 0x28 && addr[1] == 0xFF && addr[2] == 0xF8 && addr[3] == 0x08 && addr[4] == 0x65 && addr[5] == 0x04 && addr[6]==0x00 &&addr[7] == 0x67 )
else if (addr[0] == 0x28 && addr[1] == 0xFF && addr[2] == 0xB7 && addr[3] == 0x0C && addr[4] == 0x65 && addr[5] == 0x04 && addr[6]==0x00 &&addr[7] == 0xEF )
else if (addr[0] == 0x28 && addr[1] == 0xFF && addr[2] == 0xAD && addr[3] == 0x08 && addr[4] == 0x65 && addr[5] == 0x04 && addr[6]==0x00 &&addr[7] == 0x20 )

  unsigned long now = millis();
  if  (now - last_sent >= interval)
    last_sent = now;
 payload_t payload = { millis(),A,Temp, light_lvl, Humidity, Soil, Soilb, nRainVal, bIsRaining, packets_sent++ };   //δηλώσει των μεταβλητών και με την σειρά που  είναι
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header, &payload, sizeof(payload));
    if (ok)

what t the hell

A bug that caused the linker to barf with that error message under an unpredictable set of conditions (particularly on Windows XP or when installed to Win8/10 via windows store), which was present in all 1.6.x versions was fixed in 1.8.3 (or maybe 1.8.4 - either way it's fixed now) - so if you're using an older version, you should update to the latest one.

If you have ever used board manager to update the AVR board package you will need update that too (once you upgrade it with board manager, that version stays through reinstall of the IDE)