Archived

This topic is now archived and is closed to further replies.

PIPE_BOMB

GCC and math.h problem

Recommended Posts

I have just started programming in linux and I am porting some of my software. I need to use the math functions. I was getting errors about "undefined reference sqrt" when compiling with gcc. I thought it was something wrong with my code, so I checked the man pages for ''sqrt'' and made a small test program which has the same error. #include int main () { double test_var; test_var = sqrt(3.00f); return 0; } I used this line to compile the file: gcc -o test test.c I am using Mandrake 8.1, gcc 2.9.6 and glibc 2.2.4 I am I missing something? thanks in advance for any help!

Share this post


Link to post
Share on other sites
make sure the function is declared in "math.h" and that you are binding "glibc" correctly and it contains the "sqrt" function definition.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
thanks for the help, it pointed me to the problem. Other people have been having the the problem. You need to add -lm to link the maths library.

Share this post


Link to post
Share on other sites