title: Linking two .cpp and a .h files
body: <p>I'm doing an exercise (from the third chapter of Thinking in C++) but I have a problem linking two .cpp files.<br />
  <br />
  This is the exercise:</p>
  <blockquote>
  <p>Create a header file (with an extension of ‘.h’). In this file,
  declare a group of functions by varying the argument lists
  and return values from among the following: void, char,
  int, and float. Now create a .cpp file that includes your
  header file and creates definitions for all of these
  functions. Each definition should simply print out the
  function name, argument list, and return type so you
  know it’s been called. Create a second .cpp file that
  includes your header file and defines int main( ),
  containing calls to all of your functions. Compile and run
  your program.</p>
  </blockquote>
  <p>I've created the three files, but when I try to compile the compiler give me this error:</p>
  <blockquote>
  <p>undefined reference to `func1()'</p>
  <p>undefined reference to `func2(int)'|</p>
  <p>undefined reference to `func3(char, int, double)'|</p>
  <p>undefined reference to `func4()'|</p>
  <p>||=== Build finished: 4 errors, 0 warnings ===|</p>
  </blockquote>
  <p>Why it cannot found the function declaration?</p>
  <p><strong>##EDIT</strong> <br />
  These are my three files:<br /></p>
  <p>func_ex.h</p>
  <pre><code>void func1(void);
  int func2(int i);
  char func3(char c, int i, double d);
  float func4(void);
  </code></pre>
  <p>func_ex.cpp</p>
  <pre><code>#include &quot;func_ex.h&quot;
  using namespace std;
  
  void func1(void) {
      cout &lt;&lt; &quot;void func1(void)&quot; &lt;&lt; endl;
  }
  
  int func2(int i) {
      cout &lt;&lt; &quot;int func2(int i)&quot; &lt;&lt; endl;
  }
  
  char func3(char c, int i, double d) {
      cout &lt;&lt; &quot;func3(char c, int i, double d)&quot; &lt;&lt; endl;
  }
  
  float func4(void) {
      cout &lt;&lt; &quot;func4(void)&quot; &lt;&lt; endl;
  }
  </code></pre>
  <p>func_ex_main.cpp</p>
  <pre><code>#include &quot;func_ex.h&quot;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main(int argc, char* argv[]) {
      func1();
      int i;
      func2(i);
      char c; double d;
      func3(c, i, d);
      func4();
  }
  </code></pre>
  <p>I'm usig GCC as compiler (and Code::Blocks as IDE, but I think that's not important).</p>