title: Linker Error C++ "undefined reference "
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix">What is an undefined reference/unresolved external symbol error and how do I fix it?</a></p>
  </blockquote>
  
  <p>Trying to compile my program via <code>g++ -o prog1 main.cpp -std=c++0x</code></p>
  <p>I get the error:</p>
  <pre><code>/tmp/cc1pZ8OM.o: In function `main':
  main.cpp:(.text+0x148): undefined reference to `Hash::insert(int, char)'
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p><strong>main.cpp</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &lt;cstdlib&gt;
  #include &lt;cstdio&gt;
  #include &lt;functional&gt;
  #include &quot;Hash.h&quot;
  
  using namespace std;
  
  int main(int argc, char *argv[]) {
  //preset prime number 
  int prime = 101;
  hash&lt;char&gt; h1;
  int key;
  Hash HashTable;
  
  // check for Request &amp; string parameters
  if(argc != 3) {
      cout &lt;&lt; &quot;Run program with 2 parameters. [Lower Case]&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;[1] insert, find, or delete&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;[2] string&quot; &lt;&lt; endl;
  }
  
  if(strcmp(argv[1], &quot;insert&quot;) == 0) {
      //Get Hash for argv[2] aka value
      key = h1(*argv[2]);
  
      //check 1
      cout &lt;&lt; &quot;Hash: &quot; &lt;&lt; key &lt;&lt; endl;
  
      key = key % prime;
  
      //check 2
      cout &lt;&lt; &quot;Mod 101 Hash: &quot; &lt;&lt; key &lt;&lt; endl;
  
      HashTable.insert(key, *argv[2]); //PROBLEM here
  
  }
  
  return 0;
  }
  </code></pre>
  <p><strong>Hash.h file:</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &quot;LinkedList.h&quot;
  using namespace std;
  
  class Hash {
  //100 slot array for hash function
  LinkedList *hashFN[100];
  
  public:
  void insert(int key, char value);
  //void deleteItem(int key);
  //char* find(int key);
  
  
  };
  </code></pre>
  <p>Any ideas? Using this to build a hash table with set size.</p>
  <p>Edit: <strong>Hash.cpp</strong> file</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &quot;Hash.h&quot;
  
  using namespace std;
  
  void Hash::insert(int key, char value){
  *hashFN[key]-&gt;addFront(value);
  cout &lt;&lt; &quot;Success!&quot; &lt;&lt; endl;
  
  }
  </code></pre>
  <p>Trying to compile via terminal now with:</p>
  <blockquote>
  <p>g++ -c Hash.cpp -o Hash.o</p>
  <p>g++ -o prog1 main.cpp Hash.o -std=c++0x</p>
  </blockquote>
  <p>It goes into an infinite loop somehow.</p>