title: undefined reference when including a header file
body: <p>I get an error when I include a header file, but not if I include the source file instead.</p>
  
  <p>The function is defined in the source file like this:</p>
  
  <pre><code>/* in User.c */
  
  struct User {
      const char* name;
  };
  
  struct User* addedUser(const char* name) {
      struct User* user = malloc(sizeof(struct User));
      user-&gt;name = name;
       return user;
  }
  </code></pre>
  
  <p>And used like this:</p>
  
  <pre><code>/* in main.c */
  
  int test_addedUser() {
      char* newName = "Fooface";
      struct User* newUser = addedUser(newName);
      assert(!strcmp(newName, newUser-&gt;name));
      return 0;
  }
  </code></pre>
  
  <p>This works great. I am able to call test_addUser without a problem when I #include "User.c".</p>
  
  <p>However, I would like to #include "User.h" instead, which is located in the same directory:</p>
  
  <pre><code>/* in User.h */
  
  struct User {
      const char* name;
  };
  
  struct User* addedUser(const char*);
  </code></pre>
  
  <p>But, if I #include "User.h" instead of User.c, I get an error:</p>
  
  <pre><code>CMakeFiles/run_tests.dir/src/tests.c.o: In function `test_addedUser':
  /home/rid/port/src/tests.c:(.text+0x4eb): undefined reference to `addedUser'
  </code></pre>
  
  <p>It seems strange to me that the reference works just fine when including the source file User.c but it is unable to reconcile User.h.</p>
  
  <p>Any ideas why this might be?</p>