tags:

views:

91

answers:

2

How do I use pow() and sqrt() function in Ubuntu? I have included the math.h header file but it still gives me an error.

+8  A: 

Try adding -lm to your linker command. Most of the math functions live in libm which needs to be explicitly linked in.

developmentalinsanity
Thankyou.... :)
Pavitar
+5  A: 

Link to libm.so, adding -lm to the compiler command line parameters.

Matias Valdenegro
ok so what your sayings is .. that I should add -lm after cc in my compiler command,is it?
Pavitar
Yes, exactly. (filler).
Matias Valdenegro
Put the `-lm` at the end of the line, after all .o files and other libraries. Generally, put `-lsomething` after all the .o files, so that as you read the line left to right, the linker can find all the functions it should be including without rescanning the line. Yes, some environments support putting things in any order at all, but this rule of thumb will save you a lot of pain when moving to platforms that don't. Note that most toolchains on Windows prefer this order, for example.
RBerteig
Thankyou.... :)
Pavitar