ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am a newbie to LINUX and C generally. I am using RH71, and trying to learn C.
I am trying to compile a simple program in C, using the gcc compiler. Every time I try to use functions sqrt or pow, I get a compile error
undefined reference to "sqrt"
( or undefined refernce to "pow", if I use that function)
I tried compiling under Windows, and it works fine, so the code is probably OK
I tried compiling under the KDevelop IDE, and got the same error.
I tried commenting out the line #include <math.h>, and got the same error, which may mean that the compiler can't find the header files (but it finds stdio.h alright).
I tried directing the incude direction to /usr/include/math.h, but I get the same error.
I tried looking through the gcc documentation, which is comprehensive but hard work, and couldn't find any answers.
Do I need to set up or configure gcc in some way? What else should I check? Any help would be very much appreciated.
Thanks for the help - I worried at this for a few hours. before posting, which is part of the learning curve. Just my luck that the first header I try to use other than stdio.h happened to be math.h with an interesting error.
For anyone interested in getting KDevelop to compile with the math.h library, in addition to the "#include <math.h>" in your program, I found you have to edit the "Makefile" file in your "projectname/projectname" directory and find the line that says
all_libraries =
and make it look like
all_libraries = -lm (that's -LM if it were uppercase)
I just discovered what's probably easier than editing the Makefile everytime you add a file to your project....simply go to the Project->Options->Linker Options menu and check the box that says "math". I haven't tried it yet but I'm sure this is what I should have done in the first place.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.