NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Help needed with compiler diagnostic

June 13, 2012
by dicko
dicko's Avatar

I am using a variety of trigonometric functions and get a similar variety of the following diagnostic. Can anybody help?

c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr5libc.a (atan2.o): In function 'atan2': (.text.avr-linc.fplib+0x70): relocation truncated to fit: R_AVR_13_PCREL against symbol '_addsf3' defined in .text section in c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/avr5libgcc.a(_addsub_st.o)

I initially thought that I might be running out of mmemory so I switched to a 328 and get the same set of diagnostics.

Thanks for any help you can provide.

 -Dick-
June 13, 2012
by pcbolt
pcbolt's Avatar

@ dicko

I just tested a program with atan2() in it and all went well. MCU memory should not be a problem since you can compile a program without uploading it. You have a later version of Winavr then I do (I got mine from Nerdkits download section) so maybe there is something odd with the newer version. If you can, try posting your Makefile. I know you need to have a linker setting of "-lm" but sometimes the compiler does not know which directory to search. Also, there are a bunch of math libraries and it may not get the right one so it's possible you need to include the full directory path to the library file.

June 13, 2012
by dicko
dicko's Avatar

Here is my Makefile. I had '-lm' at the end of LINKFLAGS= but removed it based upon another thread with similar diagnostics.

GCCFLAGS=-g -Os -Wall -mmcu=atmega328p LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt AVRDUDEFLAGS=-c avr109 -p m328p -b 115200 -P COM1 LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

all: gps-sim-upload

gps-sim.hex: gps-sim.c make -C ../libnerdkits avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o gps-sim.o gps-sim.c ${LINKOBJECTS} avr-objcopy -j .text -j .data -O ihex gps-sim.o gps-sim.hex

gps-sim.ass: gps-sim.hex avr-objdump -S -d gps-sim.o > gps-sim.ass

gps-sim-upload: gps-sim.hex avrdude ${AVRDUDEFLAGS} -U flash:w:gps-sim.hex:a

June 14, 2012
by Tyron
Tyron's Avatar

Hey Guys,

Here it is: I've made my first attempt at downloading tempsensor.edu. The command window came back with a whole bunch of goodies. Most importantly, for learning's sake, I would like to go through each error carefully for understanding. So, here is what I think is the first problem: Beginning with;

avr-gcc -g -Os -Wall -mmcu=atmega168  -W1,-u,vfprintf -lprintf_flt -W1,-u,vfsanf -lscanf_flt -lm -o tempsensor.o tempsensor.c ../libnerdkits/deley.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

Followed by;

tempsensor.c: In function 'adc_init':

Follewed by;

tempsensor.c:35: error: expected expression before '=' token

Then it goes on to;

tempsensor.c: In function 'main' :

Now I think I may have found the problem, you let me know. I noticed a difference between the .c file and my edited .edu program. In the first block, on the last line, I put a space in between the "|" and the "=" in the ADCSRA |= (1<<ADSC)); line. I'll reload with the redaction and let you know if that error goes away.

June 14, 2012
by dicko
dicko's Avatar

OK, I have simplified my orginal program down to a one-line program that will generate the R_AVR_13_PCREL error referenced in the original message in this thread.

Any help out there?

// testbed.c

#include <math.h>

float slope, angle_a;

int main(void) {

    angle_a = atan(slope/100);

return 0;
}

Thanks,

-Dick-

June 14, 2012
by Ralphxyz
Ralphxyz's Avatar

Hey Dick have you Googled R_AVR_13_PCREL?

There are some good discussions and solutions.

Ralph

June 14, 2012
by dicko
dicko's Avatar

Yes, I spent some time reading Google citations before I started this thread. Many of the posts seem to be specific to Ardino and many seem to be random changes to makefiles and libraries. I was unable to find any specific, concrete explanations and fixes.

Having said that, mrobbins his very self explained in another thread on this forum that by simply moving the '-lm' flag from LINKFLAGS to LINKOBJECTS could cause libraries to load differently. I tried it and it worked both in my big program and in the little demo program posted above. Thanks Mike.

It is interesting to note that in my little testbed program above, that the error goes away if the global variables slope and angle_a are moved inside main to become local variables.

Who knows???

-Dick-

Post a Reply

Please log in to post a reply.

Did you know that a motor's no-load current at a given voltage is much less than it's resistance would suggest? Learn more...