my code: (finds volume/Surface area of a sphere, in C)
#include%26lt;stdio.h%26gt;
#include%26lt;stdlib.h%26gt;
#include%26lt;math.h%26gt;
int main(void){
const double pi = 3.141592654;
double x;
double volume = (4.0*pi)/3.0, SA = 4.0*pi;
printf("Enter the radius of the sphere: ");
scanf("%lf" , %26amp;x);
volume *= pow(x,3);
SA *= pow(x,2);
printf("The volume is %f and the surface area is %f.\n", volume, SA);
return 0;
}
Compiles fine on my mac
but I get
unix2% gcc -o Sphere Sphere.c
Undefined first referenced
symbol in file
pow /var/tmp//ccMxB6b1.o
Formatting is lost here, so it says: Undefined symbol pow, first referenced in file /var/tmp//ccMxB6b1.o
on an SSH'd machine. I need it to compile on there though, as it's counting on my grade. I have to use pow, I can't just multiply them, says my assignment. So...help please?
I have a code that compiles on my end, but not on a SSH'd AFS machine?
You need to tell the linker to include the math library. This is done by adding -lm to the gcc line. Something like
gcc -o Sphere Sphere.c -lm
should work.
The manual page for the funciton should indicate what linker option/library is needed. So you should be able to figure errors like this out by using the command:
man pow
land survey
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment