title: Makefile: "undefined reference to cos"
body: <p>I have just started learning about makefile files. I created a program that consists of two functions and wanted to use a makefile to put it all together. This is my file:</p>
  
  <pre><code>#Makefile
  
  all: main
  
  main: main.o find_root.o
      clang -o main main.o find_root.o
  
  main.o: main.c
      clang -c -Wall --pedantic -std=c11 main.c -lm
  
  find_root.o: find_root.c
      clang -c -Wall --pedantic -std=c11 find_root.c -lm
  
  clean: rm -f main *.o*
  </code></pre>
  
  <p>However, when I run this, I get an error - "undefined reference to cos". I am using the cosine functions in my program, but I have already linked the library to the compilation of those two files. I thought about adding "-lm" to the first clang option as well. This led to no errors, but it made a warning instead - saying that "-lm linker is unused". What should I change in my file?</p>