title: How to compile a C++ program via Terminal Mac
body: <p>I have a question on how to compile a C++ program in Terminal Mac. My program has a header file and a main file. I know that I can't compile both the header file and the main file. and just to compile the main file. I also know that I need to create a name for storing the compiled file. Here is my compile command that I used <code>g++ -o execute1 main.cpp</code> and I get this:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
  "add(int, int)", referenced from:
    _main in main-f2nZvj.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>How can I fix this? Any help will be greatly appreciated. If it helps, below is my code for the two files:</p>
  
  <p>add.h:</p>
  
  <pre><code>int add(int x, int y);
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "add.h"
  
  int main(){
      using namespace std;
      cout &lt;&lt; "The sum of 9 and 9 is " &lt;&lt; add(9, 9) &lt;&lt; endl;
      return 0;
  }
  </code></pre>