Compliling error when it all seems ok

I get this error message:

/Users/RonaldPF/Downloads/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default':
(.vectors+0x68): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_26' defined in .text.__vector_26 section in core.a(HardwareSerial.cpp.o)

when trying to compile the following code:

//Real Variables
const int floors = 5;                                                    //number of floor the elevator travels to
const int functButtons = 2;                                              //numer of function buttons in the cabin (all buttons except floors)
const int menuButtons = 3;                                               //number of buttons the device contains to control the menu

//Number of LEDs
const int numLEDnum = floors + 1;                                        //real number of number LEDs
const int functLEDnum = functButtons + 1;                                //real number of function LEDs
const int menuLEDnum = menuButtons;                                      //real number of menu LEDs

//Total amount of
const int totalLEDs = functLEDnum + numLEDnum + menuLEDnum;              //Total amount of LEDs
const int totalButtons = functButtons + floors + menuButtons;            //Total amount of Buttons

//Pins assigned to Buttons
const int numButton[] = {4, 5, 6, 7, 8};                                 //pins assigned to each button in ascending order (0 to 4)
const int functButton[] = {2, 3};                                        //pins assigned to each function button in order (bottom to top)
const int menuButton[] = {9, 10, 11};                                    //pins assigned to each menu button in order
int allButtons[totalButtons];

//Pins assigned to LEDs
const int numLED[] = {27, 26, 25, 24, 23, 22};                           //LED pins ordered lowest to highest (floor 0 to 4)
const int functLED[] = {30, 29, 28};                                     //LED pins ordered bottom to top
const int menuLED[] = {33, 32, 31};                                      //LED pins ordered minus, plus, ok
int allLEDs[totalLEDs];

//Arrays for LED and Button state
boolean buttonStates[totalButtons];                                      //holds state of buttons
boolean buttonMem[totalButtons];                                         //hold last state of Buttons to compare to.
boolean LEDStates[totalLEDs];                                            //holds state of LEDs

// Variables for ButtonTranslate
String buttonName;                                                       //input var containing name and num
int length;                                                              //num of chars in buttonName
int charindex;                                                           //num of char being processed
String name;                                                             //buttonName substring containing name
int num;                                                                 //int of buttonName substring containing num

//Array for buttonRequest
boolean buttonRequest[totalButtons];                                     //holds buttons request

//Vars for SetLEDMode
const int LEDsON = 1;
const int LEDsOFF = 2;
const int followButtons = 3;
const int followSoftware = 4;
const int followBoth = 5;
boolean LEDSwitch = 1;
int followMode = 5;
/*
     _______. _______ .___________. __    __  .______   
    /       ||   ____||           ||  |  |  | |   _  \  
   |   (----`|  |__   `---|  |----`|  |  |  | |  |_)  | 
    \   \    |   __|      |  |     |  |  |  | |   ___/  
.----)   |   |  |____     |  |     |  `--'  | |  |      
|_______/    |_______|    |__|      \______/  | _|
*/

void setup() {
  Serial.begin (9600);                                                   //Start Serial connection 
  
  //compose allLEDs[] adding numLED[], functLED[] and menuLED[] info
<<>>
  
  //compose allButtons[] adding numButton[], functButton[] and menuButton[] info
<<>>
  
  //Declare LED pins as OUTPUT
  for (int i = 0; i < totalLEDs; i++) {                                  //Declare LEDs as OUTPUT
    pinMode(allLEDs[i], OUTPUT);
  }
  
  //Declare Button pins as INPUT
  for (int i = 0; i < totalButtons; i++) {                               //Declare Buttons as INPUT
    pinMode(allButtons[i], INPUT);
  }
}

/*
 __        ______     ______   .______   
|  |      /  __  \   /  __  \  |   _  \  
|  |     |  |  |  | |  |  |  | |  |_)  | 
|  |     |  |  |  | |  |  |  | |   ___/  
|  `----.|  `--'  | |  `--'  | |  |      
|_______| \______/   \______/  | _|
*/
void loop() {
  if (ButtonChange() == HIGH) {
    if (TwoButtonRequest(1, "numButton4", "numButton3") == HIGH) {
      Serial.println("You're only pressing 3 and 4"); 
    }
    if (TwoButtonRequest(1, "numButton3", "numButton2") == HIGH) {
      Serial.println("You're only pressing 2 and 3");
    }
  }
}
void ScanButtons() {                                                     //reads all buttons and stores state 
  for (int i = 0; i < totalButtons; i++) {
    buttonStates[i] = digitalRead(allButtons[i]); 
  }
}

boolean ButtonChange() {                                                 //returns HIGH if there has been a change in button state from last scan
    for (int i = 0; i < totalButtons; i++) {
      buttonMem[i] = buttonStates[i];
    }
    ScanButtons();
    for (int i = 0; i < totalButtons; i++) {
      if (buttonMem[i] != buttonStates[i]) {
        return HIGH;
      }
    }
  return LOW;
}
  
int ButtonTranslate(String buttonName) {                                 //input: numButton3, functButton0, menu2 // output: num in buttonStates
  length = buttonName.length();
  charindex = length - 1;                                                //index to 0

  while (isDigit(buttonName.charAt(charindex))) {                        //scan each char starting from the end until number is over
    charindex--;
  }
  charindex++;
  name = buttonName.substring(0, charindex);                             //extract name from begining to begining of char (0 to before charindex)
  
  if (charindex < length) {                                              //if there is a number at end
    num = buttonName.substring(charindex).toInt();                       //extract substring containing num and convert to int
  } else { 
    num = -1;                                                            //if ther isn't a number return error code
    return -1;
  }
  
  if (name == "numButton") {                                             //return num in buttonStates adding to num depending on name
    return num;
  }
  if (name == "functButton") {
    return (num + floors);
  }
  if (name == "menuButton") {
    return (num + floors + functButtons);
  }
}

void ResetButtonRequest() {                                              //Set all buttonRequest to 0
  for (int i = 0; i < totalButtons; i++) {
    buttonRequest[i] = 0;
  }
}

void AddButtonRequest(String buttonName) {                               //Add button to buttonRequest
  buttonRequest[ButtonTranslate(buttonName)] = HIGH;
}

boolean AskButtonRequest(boolean unique) {                               //Returns HIGH if buttonRequest is pressed and unique (if it has to);
  ScanButtons();
  switch (unique) {
    case HIGH:
      for (int i = 0; i < totalButtons; i++) {
        if (buttonRequest[i] != buttonStates[i]) {
          return LOW;
        }
      }
      return HIGH;
      break;
      
    case LOW:
      for (int i = 0; i < totalButtons; i++) {
        if (buttonRequest[i] == HIGH && buttonStates[i] == HIGH) {
          return HIGH;
        }
      }
      return LOW;
      break;
  }
}

boolean TwoButtonRequest(boolean unique, String buttonName1, String buttonName2) {  //Quikly requests two buttons
  ResetButtonRequest();
  AddButtonRequest(buttonName1);
  AddButtonRequest(buttonName2);
  return AskButtonRequest(unique);
}

note: I know you like all the code :stuck_out_tongue:

The error simply says compiling error in the orange rectangle after that the message mentioned earlier.
I'm pretty sure it's something with the Serial.println()s in the main loop. If I delete any one of them or replace them with another function (except Serial.print()) like digitalWrite() it compiles ands runs no problem. Any idea of what the problem might be??

I wrote a little sketch that will Serial.println() two different things in a loop and it works perfectly (I used the same functions as my real code to see if they're the problem)

Thanks for reading :smiley:

Note: Had to delete <<>> because post was too long

Here are the deleted parts:

//compose allLEDs[] adding numLED[], functLED[] and menuLED[] info
  for (int i = 0; i < numLEDnum; i++) {
    allLEDs[i] = numLED[i];
  }
  for (int i = numLEDnum; i < (numLEDnum + functLEDnum); i++) {
    allLEDs[i] = functLED[i - numLEDnum];
  }
  for (int i = (numLEDnum + functLEDnum); i < (numLEDnum + functLEDnum + menuLEDnum); i++) {
    allLEDs[i] = menuLED[i - (numLEDnum + functLEDnum)];
  }
  
  //compose allButtons[] adding numButton[], functButton[] and menuButton[] info
  for (int i = 0; i < floors; i++) {
    allButtons[i] = numButton[i];
  }
  for (int i = floors; i < (floors + functButtons); i++) {
    allButtons[i] = functButton[i - floors];
  }
  for (int i = (floors + functButtons); i < (floors + functButtons + menuButtons); i++) {
    allButtons[i] = menuButton[i - (floors + functButtons)];
  }

What target board do you have configured? It compiles OK for me in Arduino 1.02 with Arduino Uno as target, although the following warnings are produced in verbose mode:

sketch_jan02a.ino: In function 'boolean AskButtonRequest(boolean)':
sketch_jan02a.ino:190: warning: control reaches end of non-void function
sketch_jan02a.ino: In function 'int ButtonTranslate(String)':
sketch_jan02a.ino:157: warning: control reaches end of non-void function

What board are you compiling for? Deleting Serial.print() statements making things better is generally a sign that you are running out of memory, but the pin numbers make it appear that you have a Mega, so memory should not be a problem.

Instead of snipping code, and expecting us to reinsert it, attach the code, using the Additional Options link.

Instead of snipping code, and expecting us to reinsert it, attach the code, using the Additional Options link.

Thanks, didn't think of attaching it.

the pin numbers make it appear that you have a Mega

I am, indeed, compiling for Arduino Mega 2560 on Arduino 1.0.3.

Deleting Serial.print() statements making things better is generally a sign that you are running out of memory

I am planning to add a huge array so it worries me you talk about lacking memory, I should start thinking about getting an EEPROM.
The compiler says "Binary sketch size: 7,572 bytes (of a 258,048 byte maximum)" so I wasn't worrying but I've read arrays are stored in RAM, maybe it would help a bit to #define all constants. How much RAM does the MEGA have and how can I know how much is being used?

What does this mean:

warning: control reaches end of non-void function

Thanks, didn't think of attaching it.

You forgot again.

RonaldPoFo:
What does this mean:

warning: control reaches end of non-void function

It means that in certain situations, the end of a function whose return type is not void will be reached without anything having been returned.

It is happening because of this function:

int ButtonTranslate(String buttonName) {
  ...
  
  if (charindex < length) {                                              //if there is a number at end
    num = buttonName.substring(charindex).toInt();                       //extract substring containing num and convert to int
  } else { 
    num = -1;                                                            //if ther isn't a number return error code
    return -1;
  }
  
  if (name == "numButton") {                                             //return num in buttonStates adding to num depending on name
    return num;
  }
  if (name == "functButton") {
    return (num + floors);
  }
  if (name == "menuButton") {
    return (num + floors + functButtons);
  }
  //<-- This is the end of a non-void function...
}

What happens if charindex < length and name == "Bob?" //just an example there is no return statement reached before the end of the function, so what does it return?

Fix that mistake and the PCREL error goes away:

int ButtonTranslate(String buttonName) {                                 //input: numButton3, functButton0, menu2 // output: num in buttonStates
  length = buttonName.length();
  charindex = length - 1;                                                //index to 0

  while (isDigit(buttonName.charAt(charindex))) {                        //scan each char starting from the end until number is over
    charindex--;
  }
  charindex++;
  name = buttonName.substring(0, charindex);                             //extract name from begining to begining of char (0 to before charindex)
  
  if (charindex < length) {                                              //if there is a number at end
    num = buttonName.substring(charindex).toInt();                       //extract substring containing num and convert to int
  } else { 
    num = -1;                                                            //if ther isn't a number return error code
    return -1;
  }
  
  if (name == "numButton") {                                             //return num in buttonStates adding to num depending on name
    return num;
  }
  if (name == "functButton") {
    return (num + floors);
  }
  if (name == "menuButton") {
    return (num + floors + functButtons);
  }
  return -1; //<-- This is the end of a non-void function... If it gets here, return an error code?
}

How much RAM does the MEGA have and how can I know how much is being used?

8K and there is no easy way, since the amount of RAM being used changes all the time. As function calls are made, data is pushed onto the stack, using RAM. As returns happen, values are popped off the stack, freeing RAM. Local variables are created on the heap, in RAM. As they go out of scope, they are deleted.

RonaldPoFo:
The compiler says "Binary sketch size: 7,572 bytes (of a 258,048 byte maximum)"

The mega has 8k of RAM, but the "sketch size" message doesn't indicate how much RAM is being used.

RonaldPoFo:
it would help a bit to #define all constants.

The compiler will try to keep constants out of RAM, so there is really no need to define them.

it would help a bit to #define all constants.

The compiler will try to keep constants out of RAM, so there is really no need to define them.

So what is define for then?

Fix that mistake and the PCREL error goes away:

Thanks

the following warnings are produced in verbose mode

How can I see them?

Any clue about the reason of the compiling error??

/Users/RonaldPF/Downloads/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default':
(.vectors+0x68): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_26' defined in .text.__vector_26 section in core.a(HardwareSerial.cpp.o)

What does it mean anyway?

RonaldPoFo:
I am planning to add a huge array so it worries me you talk about lacking memory, I should start thinking about getting an EEPROM.
The compiler says "Binary sketch size: 7,572 bytes (of a 258,048 byte maximum)" so I wasn't worrying but I've read arrays are stored in RAM, maybe it would help a bit to #define all constants. How much RAM does the MEGA have and how can I know how much is being used?

If you are worried about running out of RAM, then you need to:

  1. Stop using the String class and use char arrays instead;

  2. Where possible, put string literals and any constant arrays you may be using in PROGMEM.

  1. Stop using the String class and use char arrays instead;

Is it worth making thisint ButtonTranslate(String buttonName) a bit more code and stop using String? Does String really use that much RAM?

RonaldPoFo:

  1. Stop using the String class and use char arrays instead;

Is it worth making thisint ButtonTranslate(String buttonName) a bit more code and stop using String? Does String really use that much RAM?

Not only does the String class use a lot of RAM, it also causes memory fragmentation. I don't see why you need to use strings at all to name the buttons. Why not use an enumeration to name the buttons instead? Like this

enum ButtonName { numButton, numButton1, numButton2, menuButton, functButton };
...
int ButtonTranslate(ButtonName bName)
{
  ...
  if bName == numButton) {
  }
...

Not only does the String class use a lot of RAM, it also causes memory fragmentation. I don't see why you need to use strings at all to name the buttons. Why not use an enumeration to name the buttons instead? Like this

enum ButtonName { numButton, numButton1, numButton2, menuButton, functButton };

...
int ButtonTranslate(ButtonName bName)
{
  ...
  if bName == numButton) {
  }
...

Cool thanks!!

Right so, if RAMs not a problem with a MEGA and it compiles on a UNO (not code not board), what's it then??

Basically what this means:

relocation truncated to fit: R_AVR_13_PCREL

is that due to the way the compiler has organised the code, one block of code is too far from another for the compiler to get to it.
An AVR has two commands, RJMP and JMP, which the compiler uses to instruct it to jump from one bit of code to another (in this case from the vector table at the beginning to the hardware serial interrupt vector code). These commands are only capable of causing a jump of a certain amount of memory, and if the number of lines that need to be skipped (jumped over) is too large then that number will be truncated (imagine trying to store a 10bit number in a byte - it gets truncated to fit).

I have had a look at the compiled version of the code, and it appears to stick the loop(), setup(), all of your button functions and the alloc(),malloc(),realloc(), free() functions between the vector table and the hardware serial interrupt routine. By removing either of the Serial.print() calls, the length of the loop() function is reduced in size by just enough that the compiler can make the jump. It is not a RAM issue here, and it is not just Serial.print(). If you remove one of the if statements in the loop() function but leave the Serial.print() statements it fixes the error as well.

I am not sure why the lack of a return statement in one of your functions makes the jump to large. It is most likely that it confused the compiler for some yet to be determined reason.
Interestingly, adding more code made the PCREL error go away as well. Jut for nonsense sake i added this:

void test() {
  String boo = String(2,DEC);
  if (boo == "2")
  Serial.print("BLAH");
}

After the buttonTranslate() function and called it from the loop function and that cured the PCREL error.

Wow, had to read that a few times to get around it XD Thanks for the explanation Tom Carpenter, just a couple things I don't get:

the vector table at the beginning to the hardware serial interrupt vector code

What are those??

By removing either of the Serial.print() calls, the length of the loop() function is reduced in size by just enough that the compiler can make the jump.

So a program could not compile because it's too long even though there is more than enough memory?

adding more code made the PCREL error go away as well

Without deleting the Serial.print()s?

RonaldPoFo:

adding more code made the PCREL error go away as well

Without deleting the Serial.print()s?

Yeah, weird huh.

A vector table in this context is a series of lines of code stored at specific memory addresses at the beginning of the program that instruct the AVR what part code to execute in the event of an interrupt occuring.
This is the one from your code (you don't have to read through it, I'm just posting it as an example):

00000000 <__vectors>:
       0:	04 c1       	rjmp	.+520    	; 0x20a <__dtors_end>
       2:	00 00       	nop

       4:	2f c1       	rjmp	.+606    	; 0x264 <__bad_interrupt>
       6:	00 00       	nop

       8:	2d c1       	rjmp	.+602    	; 0x264 <__bad_interrupt>
       a:	00 00       	nop

       c:	2b c1       	rjmp	.+598    	; 0x264 <__bad_interrupt>
       e:	00 00       	nop

      10:	29 c1       	rjmp	.+594    	; 0x264 <__bad_interrupt>
      12:	00 00       	nop

      14:	27 c1       	rjmp	.+590    	; 0x264 <__bad_interrupt>
      16:	00 00       	nop

      18:	25 c1       	rjmp	.+586    	; 0x264 <__bad_interrupt>
      1a:	00 00       	nop

      1c:	23 c1       	rjmp	.+582    	; 0x264 <__bad_interrupt>
      1e:	00 00       	nop

      20:	21 c1       	rjmp	.+578    	; 0x264 <__bad_interrupt>
      22:	00 00       	nop

      24:	1f c1       	rjmp	.+574    	; 0x264 <__bad_interrupt>
      26:	00 00       	nop

      28:	1d c1       	rjmp	.+570    	; 0x264 <__bad_interrupt>
      2a:	00 00       	nop

      2c:	1b c1       	rjmp	.+566    	; 0x264 <__bad_interrupt>
      2e:	00 00       	nop

      30:	19 c1       	rjmp	.+562    	; 0x264 <__bad_interrupt>
      32:	00 00       	nop

      34:	17 c1       	rjmp	.+558    	; 0x264 <__bad_interrupt>
      36:	00 00       	nop

      38:	15 c1       	rjmp	.+554    	; 0x264 <__bad_interrupt>
      3a:	00 00       	nop

      3c:	13 c1       	rjmp	.+550    	; 0x264 <__bad_interrupt>
      3e:	00 00       	nop

      40:	11 c1       	rjmp	.+546    	; 0x264 <__bad_interrupt>
      42:	00 00       	nop

      44:	0f c1       	rjmp	.+542    	; 0x264 <__bad_interrupt>
      46:	00 00       	nop

      48:	0d c1       	rjmp	.+538    	; 0x264 <__bad_interrupt>
      4a:	00 00       	nop

      4c:	0b c1       	rjmp	.+534    	; 0x264 <__bad_interrupt>
      4e:	00 00       	nop

      50:	09 c1       	rjmp	.+530    	; 0x264 <__bad_interrupt>
      52:	00 00       	nop

      54:	07 c1       	rjmp	.+526    	; 0x264 <__bad_interrupt>
      56:	00 00       	nop

      58:	05 c1       	rjmp	.+522    	; 0x264 <__bad_interrupt>
      5a:	00 00       	nop

      5c:	0c 94 f2 0d 	jmp	0x1be4	; 0x1be4 <__vector_23>

      60:	01 c1       	rjmp	.+514    	; 0x264 <__bad_interrupt>
      62:	00 00       	nop

      64:	1f c7       	rjmp	.+3646   	; 0xea4 <__vector_25>
      66:	00 00       	nop

      68:	0c 94 96 08 	jmp	0x112c	; 0x112c <__vector_26>

      6c:	fb c0       	rjmp	.+502    	; 0x264 <__bad_interrupt>
      6e:	00 00       	nop

      70:	f9 c0       	rjmp	.+498    	; 0x264 <__bad_interrupt>
      72:	00 00       	nop

      74:	f7 c0       	rjmp	.+494    	; 0x264 <__bad_interrupt>
      76:	00 00       	nop

      78:	f5 c0       	rjmp	.+490    	; 0x264 <__bad_interrupt>
      7a:	00 00       	nop

      7c:	f3 c0       	rjmp	.+486    	; 0x264 <__bad_interrupt>
      7e:	00 00       	nop

      80:	f1 c0       	rjmp	.+482    	; 0x264 <__bad_interrupt>
      82:	00 00       	nop

      84:	ef c0       	rjmp	.+478    	; 0x264 <__bad_interrupt>
      86:	00 00       	nop

      88:	ed c0       	rjmp	.+474    	; 0x264 <__bad_interrupt>
      8a:	00 00       	nop

      8c:	eb c0       	rjmp	.+470    	; 0x264 <__bad_interrupt>
      8e:	00 00       	nop

      90:	49 c7       	rjmp	.+3730   	; 0xf24 <__vector_36>
      92:	00 00       	nop

      94:	0c 94 d5 08 	jmp	0x11aa	; 0x11aa <__vector_37>

      98:	e5 c0       	rjmp	.+458    	; 0x264 <__bad_interrupt>
      9a:	00 00       	nop

      9c:	e3 c0       	rjmp	.+454    	; 0x264 <__bad_interrupt>
      9e:	00 00       	nop

      a0:	e1 c0       	rjmp	.+450    	; 0x264 <__bad_interrupt>
      a2:	00 00       	nop

      a4:	df c0       	rjmp	.+446    	; 0x264 <__bad_interrupt>
      a6:	00 00       	nop

      a8:	dd c0       	rjmp	.+442    	; 0x264 <__bad_interrupt>
      aa:	00 00       	nop

      ac:	db c0       	rjmp	.+438    	; 0x264 <__bad_interrupt>
      ae:	00 00       	nop

      b0:	d9 c0       	rjmp	.+434    	; 0x264 <__bad_interrupt>
      b2:	00 00       	nop

      b4:	d7 c0       	rjmp	.+430    	; 0x264 <__bad_interrupt>
      b6:	00 00       	nop

      b8:	d5 c0       	rjmp	.+426    	; 0x264 <__bad_interrupt>
      ba:	00 00       	nop

      bc:	d3 c0       	rjmp	.+422    	; 0x264 <__bad_interrupt>
      be:	00 00       	nop

      c0:	d1 c0       	rjmp	.+418    	; 0x264 <__bad_interrupt>
      c2:	00 00       	nop

      c4:	cf c0       	rjmp	.+414    	; 0x264 <__bad_interrupt>
      c6:	00 00       	nop

      c8:	cd c0       	rjmp	.+410    	; 0x264 <__bad_interrupt>
      ca:	00 00       	nop

      cc:	6b c7       	rjmp	.+3798   	; 0xfa4 <__vector_51>
      ce:	00 00       	nop

      d0:	0c 94 14 09 	jmp	0x1228	; 0x1228 <__vector_52>

      d4:	c7 c0       	rjmp	.+398    	; 0x264 <__bad_interrupt>
      d6:	00 00       	nop

      d8:	a5 c7       	rjmp	.+3914   	; 0x1024 <__vector_54>
      da:	00 00       	nop

      dc:	0c 94 53 09 	jmp	0x12a6	; 0x12a6 <__vector_55>

      e0:	c1 c0       	rjmp	.+386    	; 0x264 <__bad_interrupt>
      e2:	00 00       	nop


... Other code in here ...


00000264 <__bad_interrupt>:
     264:	cd ce       	rjmp	.-614    	; 0x0 <__vectors>

There is one line for each of the ATMega2560's 56 interrupt sources. Each one is made up of exactly 4 bytes (2 words), which are usually either a single JMP instruction (4bytes long) or an RJMP (2 bytes, with a NOP to make it up to 4). Those which are labelled __bad_interrupt are ones which your code hasn't implemented, which means that if for some reason the processor arrives there an error must have occurred. To handle the error it jumps to a function called __bad_interrupt, which in the case of your program does the standard thing which is to the restart the program from the beginning.

Here is the one the error mentioned, __vector_26

      68:	0c 94 96 08 	jmp	0x112c	; 0x112c <__vector_26>

Notice how it neets to jump from the current line (0x0068 written on the left) to the location where the interrupt code is stored (0x112c). A JMP statement specifies an exact program memory location to move to, but it can only reference up to a 16bit address. What happens if the code is at address 0x10000? or higher? It can't get there. An Atmega has 256k of flash, but the instruction can only address 64k, so the compiler has to be careful where it places code.

You may think it is daft not being able to address all the flash, but there is actually an instruction which can. The atmega2560 has an instruction called EIJMP which is capable of addressing all of the program memory, in fact it can address up to 4MB of flash. However, it is not possible to use that instruction in the vector table as it takes 10 bytes of program memory to use it, but there is only space for 4bytes in the vector table.
Just for fun, this is how it would have to use EIJMP to get to address 0x10000. Each instructions used is 2 bytes long, and there are 5 in total which makes 10bytes.

ldi r16,0x01 ; Set up EIND and Z-pointer
out EIND,r16 
ldi r30,0x00
ldi r31,0x00
eijmp ; Jump to 0x010000

Something about your code must have made the compiler for whatever reason put the interrupt code at an address >0xFFFF

Thanks a lot for your time and super explanation, I really appreciate it!!

Something about your code must have made the compiler for whatever reason put the interrupt code at an address >0xFFFF

So probably my not defined returns, right. I mean, could a perfectly debugged code not compile because casually the length between two vectors is two big?

A good explanation, which also explains why the code compiled OK for me with a Uno as target - the Uno has only 32K of flash, so a JMP instruction can reach the entire address space.