relocation truncated to fit: R_AVR_13_PCREL

Hi, all,

I was programming mlx90614 with MEGA2560 based on modified adafruit’s library, I found a strange problem, the following code could not be compiled if line 17 was commented out, but even if this line was commented out, it could be compiled if the board was changed to UNO!

/// code snippets
#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
Serial.begin(9600);

Serial.println(“Adafruit MLX90614 test”);

mlx.begin();

Serial.println(“0-31 of EEPROM values: “);
for (int i=0; i<32;i++)
{
Serial.print(i);
//Serial.println(); //if commented out, it threw out exception when compiled
Serial.print(”,\t”);
Serial.println(mlx.readRegister(i+0x20),HEX);
}
}

the exception message as following:

…/arduinoide/arduino-1.0.2/hardware/tools/avr/bin/…/lib/gcc/avr/4.3.2/…/…/…/…/avr/lib/avr6/crtm2560.o: In function __vector_default': (.vectors+0xd8): relocation truncated to fit: R_AVR_13_PCREL against symbol __vector_54’ defined in .text.__vector_54 section in core.a(HardwareSerial.cpp.o)

It is a mismatch between optimization of the compiler and the linker. Could you try the new Arduino IDE 1.6.0 ? Do you have special options set in platform.txt ? Did you check if Adafruit has updated the library ?

This sounds like yet another out of date Adafruit lib.

Mark

It's not a bug in your code or using an old adafruit library.

I'm having almost the same problem on a Mega2560R3 with 1.5.8 as well as a fresh install of 1.6. I haven't touched my platforms.txt.

/Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr6/libc.a(isspace.o): In function `isspace':
(.text.avr-libc+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `__ctype_isfalse' defined in .text.avr-libc section in /Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr6/libc.a(cty_isfalse.o)
collect2: error: ld returned 1 exit status
Error compiling.

Read the responses here: http://stackoverflow.com/questions/8188849/avr-linker-error-relocation-truncated-to-fit

Something to do with the linker using relative rather than absolute jumps and calls.

I'm not sure why this isn't a problem with 1.0.6, but I can compile fine on the older version.