title: What is missing in my makefile?
body: <p>I am trying to create my first makefile.  I tested my program by using the following commands:</p>
  
  <pre><code>Command 1: gcc -Wall -ggdb3 -std=c99 -o file1 file1.c -lm -lpthread -l
  Command 2: gcc -Wall -ggdb3 -std=c99 -o file2 file2.c -lm -lpthread
  </code></pre>
  
  <p>Everything works great. Then I created a makefile (please see below).  I keep getting an error message. Can someone take a look at my code and give me a hint on what the problem is?</p>
  
  <pre><code>file2.o: In function `seed_primes':
  file2.c:(.text+0x461): undefined reference to `sqrt'
  file2.c:(.text+0x466): undefined reference to `sqrt'
  file2:(.text+0x533): undefined reference to `sqrt'
  file2.o: In function `create_threads':
  file2.c:(.text+0x668): undefined reference to `pthread_create'
  file2.c:(.text+0x6b5): undefined reference to `pthread_join'
  file2.o: In function `next_seed':
  file2.c:(.text+0x860): undefined reference to `sqrt'
  collect2: ld returned 1 exit status
  make: *** [file2] Error 1
  </code></pre>
  
  <p>Here is my makefile:</p>
  
  <pre><code>CC=gcc
  DEBUG=-ggdb3
  CFLAGS=#(DEBUG) -Wall -lm -lpthread -lrt -l
  
  PROGS=file1 file2 
  
  all: $(PROGS) 
  
  file1: file1.o
      $(CC) $(CFLAGS) -o file1 file1.o 
  
  file1.o: file1.c
      $(CC) $(CFLAGS) -c file1.c     
  
  file2: file2.o
      $(CC) $(CFLAGS) -o file2 file2.o 
  
  file2.o: file2.c
      $(CC) $(CFLAGS) -c file2.c  
  
  clean:
      rm -f $(PROGS) *.o *~
  </code></pre>