seriouslylinux
August 19th, 2013, 12:23 AM
I am using GCC on Ubuntu 12.10. I am trying to use math functions; specifically sqrt(). When I use a line of code that has a constant in it "sqrt(4)" the function compiles and gives me the right answer in the terminal. When I use a variable "sqrt(number)" the compiler returns with "undefined reference to `sqrt'". I believe I need to use the linker to a math library since I encountered this same problem with Netbeans. I do not know and am not able to find the name of the library or file that would solve this problem. I have tried "-std=iso9899:1990" since that std requires only <math.h> and I still get the same error message. Here is the snippet of code from the program:
double number;
printf ("Enter a number: ");
scanf("%lf", &number);
printf ("The sqrt of 4 is: %lf\n", sqrt(4));
printf ("The sqrt of your number is: %lf\n", sqrt(number));
double number;
printf ("Enter a number: ");
scanf("%lf", &number);
printf ("The sqrt of 4 is: %lf\n", sqrt(4));
printf ("The sqrt of your number is: %lf\n", sqrt(number));