Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to 'sqrt' from math.h on PS3 with YDL 6.1 and Cell SDK 3.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?

like image 623
Paul Wicks Avatar asked Feb 02 '26 00:02

Paul Wicks


1 Answers

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.

like image 107
schnaader Avatar answered Feb 04 '26 00:02

schnaader



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!