views:

719

answers:

1

I have a PS3 that I've installed YDL 6.1 and SDK 3.1 on and everything seems to be working fine, as I can compile and run the examples. However, I've run into some problems with writing programs of my own. I've created a small test case that seems to pinpoint the cause of the failure. I have the following code:

// mathtest.c
#include <stdio.h>
#include <math.h>

int main ()
{
  double param, result;
  param = 1024.0;
  result = sqrt (param);
  printf ("sqrt(%lf) = %lf\n", param, result );
  return 0;
}

When I then run

ppu-gcc mathtest.c

I get the following error

/tmp/ccFqwJdG.o:(.text+0x20): undefined reference to `sqrt'
collect2: ld returned 1 exit status

I already checked to make sure that math.h exists on this system and it does define sqrt. I also already tried running this:

ppu-gcc -I/usr/includes/ mathtest.c

but it results in the same error. I'm confused, anyone have any ideas?

+3  A: 

I sometimes got similar errors on Linux, using -lm as a gcc parameter helped there. Perhaps it does here, too. The parameter tells the linker to include the math library, too.

schnaader
Yeah, that seems to fix it. Strange how some platforms (Linux) require linking against math, while others don't (OS X), although the reasons that os x doesn't require linking could stem from a number of sources (libc vs apple libs, apples modifications to gcc, etc).
Paul Wicks