title: Why am I getting "undefined reference to sqrt" error even though I include math.h header?
body: <p>I'm very new to C and I have this code: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  int main(void)
  {
    double x = 0.5;
    double result = sqrt(x);
    printf("The square root of %lf is %lf\n", x, result);
    return 0;
  }
  </code></pre>
  
  <p>But when I compile this with:</p>
  
  <pre><code>gcc test.c -o test
  </code></pre>
  
  <p>I get an error like this:</p>
  
  <pre><code>/tmp/cc58XvyX.o: In function `main':
  test.c:(.text+0x2f): undefined reference to `sqrt'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Why does this happen? Is <code>sqrt()</code> not in the <code>math.h</code> header file? I get the same error with <code>cosh</code> and other trigonometric functions. Why?</p>