Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1242
  • Last Modified:

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.
0
sutejok
Asked:
sutejok
  • 2
1 Solution
 
hongjunCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now