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
2010-08-24 17:33:41
Thankyou.... :)
Pavitar
2010-08-25 11:01:30
+5
A:
Link to libm.so, adding -lm to the compiler command line parameters.
Matias Valdenegro
2010-08-24 17:33:45
ok so what your sayings is .. that I should add -lm after cc in my compiler command,is it?
Pavitar
2010-08-24 17:52:40
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
2010-08-24 23:55:04