I am having problems in math.h header file and when I use square root function as in sqrt(d). But my compiler is not supporting this. Please advise me about this problem.

My Ubuntu version is 2012.

share|improve this question

closed as off-topic by Sergiy Kolodyazhnyy, TheWanderer, muru, Seth Mar 12 '16 at 23:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Sergiy Kolodyazhnyy, muru, Seth
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Whilst we love programming questions - the question must be related to Ubuntu - can you clarify in detail what the issue is here - examples etc? – fossfreedom Aug 15 '13 at 10:37
    
it is like sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))... my compiler is not supporting this command – shreya Aug 15 '13 at 10:43
1  
please respond by editing your question. Give code examples, how you are compiling, version of ubuntu, version of the compiler, have you tried to do this on another compiler/distro. What happens etc? – fossfreedom Aug 15 '13 at 10:45
1  
@shreya Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance. – Braiam Aug 15 '13 at 11:07
    

Append -lm to the end of your gcc command.

With all recent versions of GCC on GNU/Linux systems like Ubuntu, when you use the math library, you have to explicitly link to it. It is not automatically linked to along with the rest of the standard C library.

If you are compiling on the command-line with the gcc or g++ command, you would accomplish this by putting -lm at the end of the command.

For example: gcc -o foo foo.c -lm

share|improve this answer

If you are going to compile a C program with math.h library in LINUX using GCC or G++ you will have to use –lm option after the compile command.

gcc xyz.c -o xyz -lm

Here,

gcc is compiler command (compiler name)
xyz.c is a source file name.
-o is an option to specify the output file.
xyz is the name of the output file.
-lm is an option to link againt the math library (libm).

for more details here is the link containing complete article on it.
Compiling C program with math.h in Linux.

share|improve this answer
    
After the linking command, not the compile command. (Sorry for the nitpicking, but getting it right helps to understand other situations). – mousomer Sep 29 '16 at 7:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.