Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> "undefined reference to `fabs'"
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1288042447

Message started by roypardi on 10/25/10 at 21:34:07

Title: "undefined reference to `fabs'"
Post by roypardi on 10/25/10 at 21:34:07
Hi - I am getting the error: undefined reference to `fabs' in a current project. In trying to track down the issue, I broke the function out into a separate sketch - where it compiles fine (of course ;-).

Wondering if there is something else I can check/try. If I switch 'fabs()' to 'abs()' in my project it will compile - but I need floats.

Set up:
--Wiring 27 (downloaded last week)
--1st gen Wiring board
--Mac OSX 10.5.8

I was able to open + compile the sketch in the Arduino IDE and compile for the 1st gen Mega board (atmega 1280).

Don't know what else I can check or test - any tips?

--thanks!


Code:
static double arc_stepangle, arc_xc, arc_yc, arc_a0, arc_r, arc_phi;
static int16_t arc_step;

void setup()
{
}

void loop()
{
}

uint8_t arc_next(int32_t* x, int32_t* y) {
  uint8_t cont = 1;

  arc_step++;
  double alpha = arc_step*arc_stepangle;
  if (fabs(alpha) > fabs(arc_phi)) {
    alpha = arc_phi;
    cont = 0;
  }
  alpha += arc_a0;

  int32_t xd = arc_xc + arc_r*cos(alpha);
  int32_t yd = arc_yc + arc_r*sin(alpha);

  //userscale(xd, yd, x, y, &user_loc.x, &user_loc.y);

  return cont;//arc_step < arc_steps ? 1 : 0;
}


Title: Re: "undefined reference to `fabs'"
Post by roypardi on 10/25/10 at 22:14:10
Ok - I am able to repro the compile error in the sketch below. If I comment out "Serial.print(cout);" then the sketch will compile. No idea what this might be about but it seems like it is not an error in my project code.

Fwiw - If I leave the print line in but just print some arbitrary val (e.g Serial.print(1)) then the sketch will compile.

Odd -


Code:
float testFloat = -1123.45;

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

void loop()
{
  float cout;

  cout = fabs(testFloat);

  Serial.print(cout);

  delay(1000);
}

Title: Re: "undefined reference to `fabs'"
Post by barragan on 10/26/10 at 06:04:20
hi Roy, that's an interesting issue, I'll dig into it. The upper sketch works just fine, the lower one works as you mentioned. The funny thing is that it only affects fabs() no other commands in the math library work as expected. sin() etc...

Title: Re: "undefined reference to `fabs'"
Post by barragan on 10/26/10 at 07:46:23
Found it, it is an option for avr-gcc compiler, I've changed it in the distribution file directly so download it again wiring-0027.dmg and replace your current installation. Let me know.

Title: Re: "undefined reference to `fabs'"
Post by roypardi on 10/26/10 at 14:50:24
Yes, my project compiles now.

Thanks for the fix!!

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.