Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Created May 20, 2012 20:40
Show Gist options
  • Save underhilllabs/2759457 to your computer and use it in GitHub Desktop.
Save underhilllabs/2759457 to your computer and use it in GitHub Desktop.
gcc #include <math.h>

from gcc FAQ

gcc faq

14.3: I'm trying to do some simple trig, and I am #including <math.h>, but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For instance, due to a longstanding bug in Unix and Linux systems, you usually need to use an explicit -lm flag, at the end of the command line, when compiling/linking. See also questions 13.25, 13.26, and 14.2.

add -lm to end of command line

gcc -o triangle triangle.c -lm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment