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.

Support Forum » Can't compile using Log function.

March 31, 2012
by Jer
Jer's Avatar
double Calc_VZout(double Read_Sim, double Ik, double Vref_uut, double Zout)
{

     double Isim = 0;
    double Vzsim = 0;
     double temp = 1;
     double temp2;

    temp2 = (temp - Read_Sim);

    if (temp2 > 0)
    {

        Isim = log(temp2) * Ik;// <= Process Exit Code: 2

        // But this will work => Isim = log(.234) * Ik;

    }

    Vzsim = (Isim * Zout);

    return (Vref_uut - Vzsim);

}

Output:
> "make.exe" all

make -C ../libnerdkits
make[1]: Entering directory `C:/WinAVR-20090313/avr/libnerdkits'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `C:/WinAVR-20090313/avr/libnerdkits'
avr-gcc -g -O0 -Wall -mmcu=atmega328p  -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm -o zsensim.o zsensim.c ../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o
c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5\libc.a(log.o): In function `log':
(.text.fplib+0x46): relocation truncated to fit: R_AVR_13_PCREL against symbol `__addsf3' defined in .text section in c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/avr5\libgcc.a(_addsub_sf.o)
c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5\libc.a(log.o): In function `log':
(.text.fplib+0x4e): relocation truncated to fit: R_AVR_13_PCREL against symbol `__addsf3' defined in .text section in c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/avr5\libgcc.a(_addsub_sf.o)
make.exe: *** [zsensim.hex] Error 1

> Process Exit Code: 2
> Time Taken: 00:01
March 31, 2012
by Jer
Jer's Avatar

I FOUND THE SOLUTION!!!

THANKS to mrobbins!

Microcontroller Programming ยป Trouble with the log10 function

June 02, 2010 by mrobbins (NerdKits Staff)

Hi Rufus, Does your compiler error say something like "relocation truncated to fit"? If so, give this a try: 1) In the Makefile, remove "-lm" from the end of the LINKFLAGS line:

1 LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt
View Original 2) In the Makefile, add "-lm" to the end of the LINKOBJECTS line:

1 LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o -lm
View Original 3) Run "make". This simply rearranges the order in which the compiler/linker bundles the math code with your code, ensuring that the math code comes last. For reasons that are a little bit voodoo, this tends to make it work. (There's a bug report about this issue from a while ago, but not too much detail in explaining it clearly.) Please let me know if that works! And if not, please post the compiler's error message. Mike

Post a Reply

Please log in to post a reply.

Did you know that any circuit of voltage sources and resistors can be simplified to a "Thevenin" equivalent circuit? Learn more...