error in function main

I have tried to compile some software that has to do with LoRa. After compiling I get this error message:

D:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp: In function 'main':

D:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp:51:1: error: unable to find a register to spill in class 'NO_REGS'



D:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp:51:1: error: this is the insn:

(insn 959 956 962 47 (set (mem:QI (post_dec:HI (reg/f:HI 32 __SP_L__)) [0  S1 A8])

        (subreg:QI (reg/f:HI 905) 1)) D:\Program Files (x86)\Arduino\libraries\arduinoLoRaWAN\arduinoLoRaWAN.cpp:1606 1 {pushqi1}

     (expr_list:REG_ARGS_SIZE (const_int 11 [0xb])


D:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp:51: confused by earlier errors, bailing out

lto-wrapper: D:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc returned 1 exit status

d:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

The code I used is this:

#//Minimote Werkend
#include <Wire.h>

// Cooking API libraries
#include <arduinoUART.h>
#include <arduinoUtils.h>

// LoRaWAN library
#include <arduinoLoRaWAN.h>

  int knop = 13;
  uint8_t error;
  uint8_t socket = SOCKET0;
void setup() {
char APP_SESSION_KEY[] = "000102030405060708090A0B0C0D004A";
char NWK_SESSION_KEY[] = "0102030405060708091011121314104A";
  error = LoRaWAN.ON(socket);
  error = LoRaWAN.setDeviceEUI();
  error = LoRaWAN.setDeviceAddr();
  error = LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);
  error = LoRaWAN.setAppSessionKey(APP_SESSION_KEY);
  error = LoRaWAN.saveConfig();
 pinMode(knop, INPUT);

void loop() {
    char data[]="";
    char k[] = "30";//0
    sprintf(data, "%s%s",data, k);
    error = LoRaWAN.ON(socket);
   // delay(100);                                        
    error = LoRaWAN.joinABP();
    error = LoRaWAN.sendUnconfirmed(3, data);
   if( error == 0 ) 
    Serial.println(F("Send Unconfirmed packet OK"));     
    if (LoRaWAN._dataReceived == true)
      Serial.print(F("   There's data on port number "));
      Serial.print(F(".\r\n   Data: "));
    Serial.print(F("Send Unconfirmed packet error = ")); 
    Serial.println(error, DEC);
 // delay(100);
  error = LoRaWAN.OFF(socket);

I have no idea where this error comes from, because with simple codes like "blinky" it works fine. I have tried multiple builds from arduino but with all these build I get the same error. Can someone help me find the cause of this problem?

The libraries for this code can be found here: Libraries LoRaWAN

Thanks in advance!

#//Minimote Werkend

Why is that # symbol there?

    char data[]="";

Creating a zero element array is pointless.

    sprintf(data, "%s%s",data, k);

The array data contains no data, so it is pointless to copy it. The array data has no room to hold more data, so it is pointless to copy data there.

Arduino is a moving target... Each new IDE version tightens-up some of the inherit sloppiness.

The example code from your link ... Did you try that? It is simple and will ensure all of the libraries are referenced (on disk) correctly.

This may have some insight, too:


Apparently this is caused by a bug in the new version of avr-gcc used by Arduino AVR Boards 1.6.12 and newer:

So there are two different solutions:

You can fix it by downgrading to an older version of the AVR core:

  • Tools > Board > Boards Manager
  • Wait for downloads to complete
  • Click on "Arduino AVR Boards"
  • Select 1.6.11 from the "Select version" dropdown menu.
  • Click Install
  • After installation is complete click "OK"

Or you can edit the arduinoLoRaWAN library to specify the O2 optimization level for the problem functions:

File > Examples > arduinoLoRaWAN > LoRaWAN_01a_configure_module_868

Sketch > Show sketch folder

Move up 2 folder levels so that you are in the libraries/arduinoLoRaWAN folder

Open arduinoLoRaWAN.h in a text editor

Change line 151 from:

uint8_t joinABP();


uint8_t joinABP() __attribute__((__optimize__("O2")));

Change line 154 from:

uint8_t sendUnconfirmed(uint8_t port, char* payload);


uint8_t sendUnconfirmed(uint8_t port, char* payload) __attribute__((__optimize__("O2")));

Save the file.