title: Makefile duplicate symbol for architecture x86_64 error?
body: <p>I am attempting to create a makefile for a simple program which relies on a simple file and a function stored in a c file. Here are the files:</p>
  
  <p>function.c:</p>
  
  <pre><code>int random_fun(int n, int m)
  {  int g;
     n = n+m;
     m=n/3;
     g=n*m;
     return g;
  }
  </code></pre>
  
  <p>main.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "function.c"
  int main()
  {
     int a, b;
     printf("Enter numbers a, and b: ");
     scanf("%d %d", &amp;a, &amp;b);
     printf("Here is ur answer: %d", random_fun(a, b));
     return 0;
  }
  </code></pre>
  
  <p>And here is my makefile:</p>
  
  <pre><code>OBJS = main.o function.o
  program: $(OBJS)
      $(CC) -o $@ $?
  clean:
      rm $(OBJS) program
  </code></pre>
  
  <p>Whenever I try type make, I get the following error:</p>
  
  <pre><code>duplicate symbol _random_fun in:
      main.o
      function.o
  ld: 1 duplicate symbol for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see 
  invocation)
  make: *** [program] Error 1"
  </code></pre>
  
  <p>Not sure what I am doing wrong. I can compile each code separately and main works. I was getting the same error for another project I was working on, so I tried with a very simple case involving only these 2 C files, and I get the same issues. I am fairly new to makefiles and what not, so bear with me if I am making a stupid mistake.</p>