title: How to use LDFLAGS in makefile
body: <p>I am new to Linux OS. I am trying to compile a <code>.c</code> file using a makefile. The math library has to be linked. My makefile looks like this:</p>
  
  <pre><code>CC=gcc
  CFLAGS=-Wall -lm
  
  all:client
  
  .PHONY: clean
  clean:
      rm *~ *.o client
  </code></pre>
  
  <p>When I run <code>make</code>, I get the following error:</p>
  
  <pre><code>"undefined reference to rint"
  </code></pre>
  
  <p>So it is not able to link the math library.</p>
  
  <p>But when I compile explicitly using</p>
  
  <pre><code>gcc client.c -lm -o client
  </code></pre>
  
  <p>it successfully compiles.</p>
  
  <p>So how should I change my makefile such that it works. I have already tried adding <code>LDFLAGS=-lm</code>. But I get the same error.</p>
  
  <p>I should also add that when I run <code>make</code>, it expands to</p>
  
  <pre><code>gcc -Wall -lm client.c -o client
  </code></pre>
  
  <p>(notice that when I run <code>gcc</code> explicitly with <code>-lm</code> at the end, it works).</p>