title: How to compile multiple .c and .h files in gcc linux?
body: <p>So I have a source mainClass.c where I have the main defined. I have a header file class1.h and the implementation of all the functions defined in class1.h in class1.c. I have two variables (global) in class1.h named cond and mutex which are being used in class1.c for now and probably in future I will be using it in my mainClass.c as well.
  Now to compile all the source files to generate one object file I am doing something as follows:</p>
  
  <p><code>gcc -Wall -pthread -I/home/2008/ariarad/mainClass1 mainClass1.c class1.c -o out</code></p>
  
  <p>/home/2008/ariarad/mainClass1 is where all my header and source files are at and I am using pthead.h in one of the .c file. Even though I have included it there it complains so I had to include it.</p>
  
  <p>Now when I run the above command the I get the following errors:</p>
  
  <pre><code>class1.c:3:16: error: redefinition of ‘cond’
  class1.h:66:16: note: previous definition of ‘cond’ was here
  class1.c:4:17: error: redefinition of ‘mutex’
  class1.h:67:17: note: previous definition of ‘mutex’ was here
  </code></pre>
  
  <p>Just in case I have an ifndef and endif block surrounding the class1.h to avoid multiple inclusion. I am definitely not redefining the variables defined in the header file in the .c file. So can someone please help me why it is still giving me the errors?</p>