sin() and cos() in math.h

I'm trying to use sin() and cos() in my program, and I'm always getting error message saying: "undefined reference to 'sin' " or "undefined reference to 'cos' ". I've included math.h. I have also make sure that the functions parameter is of type double.  I'm using Red Hat Linux operating system, and use gcc to compile my program. What seems to be the problem causing this?? Thanks for your help.
sutejokAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
hongjunConnect With a Mentor Commented:
try this when you compile

    gcc -lm yourfile.c


You need to include math library during compilation.
0
 
hongjunCommented:
Thanks for selecting my comment as the answer. But why the grade of "B"? It could have been an A grade since my comment solved your problem directly. Note that a grade A given does not differ from a grade B or C to a questionner. It will not affect your question points value but rather it only affect your grading record. Your grading record will be better if you shows consistent A grading awarding habit.

Please see Tip #11 - Grade quickly and fairly
http://cd-eepages.fateback.com/asking.html

Please explain the reason for the B grade.

hongjun
0
All Courses

From novice to tech pro — start learning today.