title: Compiling from multiple files gives "undefined reference"
body: <p>I need to provide a CFG class in a separate file, but I'm unsure how to compile it together with the associated <code>.h</code> and the main program.</p>
  
  <p>I've <code>#include</code>ed the .h file and I've asked for both files at the command line, but I'm not sure why this is wrong for compiling them together.</p>
  
  <p>Thoughts?</p>
  
  <p>CFG.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class CFG
  {
      public:
          string code[25];
          char startNT;
      //private:
  
      CFG(string inCode[], int stringLen)
      {
          for (int a = 0; a &lt; stringLen; a++)
          {
              //cout &lt;&lt; inCode[a] &lt;&lt; endl;
              this-&gt;code[a] = inCode[a];
          }
          for (int a = 0; a &lt; stringLen; a++)
          {
              cout &lt;&lt; this-&gt;code[a] &lt;&lt; endl;
          }
      }
  
      char getStartNT()
      {
          return startNT;
      }
  
      void setStartNT(char stNT)
      {
          startNT = stNT;
      }
  
      bool processData(string inString, string wkString)
      {
          //Our recursive function
          return true;
      }
  
      void garbage()
      {
          return;
      }
  };
  </code></pre>
  
  <p>CFG.h:</p>
  
  <pre><code>#ifndef _cfg_h_
  #define _cfg_h_
  
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class CFG
  {
      public:
          string code[25];
          char startNT;
  
          CFG(string inCode[], int stringLen);
          char getStartNT();
          void setStartNT(char stNT);
          bool ProcessData(string inString, string wkString);
          void garbage();
  };
  
  #endif
  </code></pre>
  
  <p>cfg_entry.cpp:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include "cfg.h"
  
  using namespace std;
  
  int main()
  {
      string inArray[5];
      inArray[0] = "test0";
      inArray[1] = "test1";
      inArray[2] = "test2";
      inArray[3] = "test3";
      inArray[4] = "test4";
      CFG * cfg1 = new CFG(inArray, 5);
      cfg1-&gt;garbage();
      return 0;
  }
  </code></pre>
  
  <p>Compile errors:</p>
  
  <pre><code>art@tv:~/Dropbox/Weber/CS 4110/Individual Assignment 2$ g++ -g -std=c++11 -Wall -o cfg_entry cfg.cpp cfg_entry.cpp
  /tmp/ccICQEd0.o: In function `main':
  /home/art/Dropbox/Weber/CS 4110/Individual Assignment 2/cfg_entry.cpp:15: undefined reference to `CFG::CFG(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;*, int)'
  /home/art/Dropbox/Weber/CS 4110/Individual Assignment 2/cfg_entry.cpp:16: undefined reference to `CFG::garbage()'
  collect2: error: ld returned 1 exit status
  </code></pre>